32 Topics

Member Avatar for
Member Avatar for JOSheaIV

As I develop more and more for a living I have been trying to perfect my developing skills with personal projects in hope to expand my professional career, one of these is the concept of Polymorphism. The last few projects I have worked on, I have this model where I …

Member Avatar for Amr.Mohammad87
0
455
Member Avatar for theashman88

Hi I'm creating a code for my class and what I'm trying to do is to create a triangle class that is derived from abstract class TwoDimShape. However; when I create the triangle class and use base as a variable I get an error. My teacher wants us to use …

Member Avatar for deceptikon
0
297
Member Avatar for moaz.amin.37

i can understand it when we want to implement polymorphism in c++ we use virtual functions and function overriding but when we want to implement polymorphism in java then we do not use virtual methods why. in java we use simply reference object that can store the address and use …

Member Avatar for Slavi
0
255
Member Avatar for theashman88

I'm trying to create a program that passes arguments of size of three shapes, a circle, a triangle, and a rectangle. I got those but everytime I run the code it displays the arguments as 0 instead of giving me the shape dimension. Here is the code. using System; class …

Member Avatar for kvprajapati
0
281
Member Avatar for mike_2000_17

# Introduction # The subject of this tutorial is a bit more advanced than the subjects I have tackled in the past, but I hope this will find some interested readers. From time to time in C++, programmers find themselves torn apart between using a *Generic Programming* style which primarily …

2
2K
Member Avatar for StephenopolousINC

Hello I am trying to create a class that called Lootable and create subclasses such as trunk, locker, etc. that will contain items that can be looted, they will inherit their lootability from the Lootable class. I am thinking of using the ArrayList for this. I have thought of different …

Member Avatar for StephenopolousINC
0
921
Member Avatar for tanatos.daniel

I have an abstract class CArticle and two derived classes CBook and CMagazine. I also have a class CLibrary where i want to add articles. Its members are an int variable to count the articles and a double pointer of CArticle. I have the following main function: int main() { …

Member Avatar for tanatos.daniel
0
444
Member Avatar for sparkthesunoff

I have two containers with the type of *A* A<string, double> s1; A<string, bool> s2; So I wrote the *A* class with the necessary functions and I used a template<class T, class E> for it. It has a function that returns a value of *E*, in my case, it returns …

Member Avatar for sepp2k
0
268
Member Avatar for rahul.ch

public class GenericDemo<E extends GenericDemo> { E innerE; public E doStuff(E e, GenericDemo<E> e2) { //insert code here } public E getE() { return innerE; } } The options are: 1. return e 2. return e2.getE() 3. return e2 4. return e.getE() Option (1) and (2) compile fine. Option (3) …

Member Avatar for ~s.o.s~
0
246
Member Avatar for rahul.ch

<? super Animal> means animal or it's superclass only. Then why inside the method it's allowing to add Dog object even though it's a subclass of Animal? This program compiles and runs! import java.util.*; class Cat {} class Animal{Animal() {System.out.println("Animal constructor");}} class Dog extends Animal{Dog() {System.out.println("Dog constructor");}} public class GenericDemo5 …

Member Avatar for rahul.ch
0
334
Member Avatar for rahul.ch

Compiles fine. But at runtime it gives ClassCastException. My doubt is that why is it so even though st which is of type Sample1 gets casted to Sample2 and generates exception even though Sample2 IS-A Sample1.

Member Avatar for rahul.ch
0
240
Member Avatar for rahul.ch

class Mixer { Mixer() {} Mixer(Mixer m) { m1 = m; } Mixer m1; public static void main(String args[]) { Mixer m2 = new Mixer(); Mixer m3 = new Mixer(m2); m3.go(); Mixer m4 = m3.m1; m4.go(); Mixer m5 = m2.m1; m5.go(); } void go() { System.out.println("hi"); } } The answer …

Member Avatar for sepp2k
0
255
Member Avatar for arunkumars

Hi all, I know that one advantage of method overloading is that the implementation can be overridden for the same method name, but wanted to know how is that going to be an advantage for us. All the links explain how to do it, and not why to do it …

Member Avatar for Mitja Bonca
0
222
Member Avatar for sciwizeh

So this is mainly a Design/Clean Coding sort of question, I know I've read something about this previously but I can't find it, I believe it's in one of my reference books on C/C++ so it wouldn't likely be useful to my predicament. This question includes a lot of Java …

Member Avatar for sciwizeh
0
243
Member Avatar for maverick420

> I'm implementation polymorphism and have one confusing that if I use instanceof then I'm trying to perform casting which voids polymorphism so will that be any way to avoid instanceof with the code and still have the program working? Block of code where I have used instanceof starts from …

Member Avatar for maverick420
0
204
Member Avatar for makehaste

I'm working on a program that demonstrates polymorphism. It asks the user to create an elementary, high school, or college student. Once a student is created, it is stored in an array list. When prompted, the program is suppose to print out each of the student's information. How do I …

0
124
Member Avatar for Kanoisa

Hi all, I have started finding lots of uses for abstract classes to define interfaces for common functionality using polymorphism and i know that using polymorphism and virtual functions incurrs some additional call cost of functions. So what im wondering is can i get the best of both worlds? consider …

Member Avatar for Kanoisa
0
191
Member Avatar for jehlaipixy

HELP ME PLEASE. I AM A 1ST YR COLLEGE STUDENT :/ Define an interface Filter as follows: public interface Filter { boolean accept(Object x); } Modify the implementation of the DataSet class to use both a Measurer and a Filter object. Only objects that the filter accepts should be processed. …

Member Avatar for jehlaipixy
0
443
Member Avatar for nikitadurgude

[CODE]#include <iostream> using namespace std; class bike { public: bike () { cout << "Bike: no parameters\n"; } bike (int a) { cout << "Bike: int parameter\n"; } void color(int a,int b) { cout<<"Inside Bike Color"<<endl; } }; class ducati : public bike { public: ducati (int a) { cout …

Member Avatar for Narue
0
209
Member Avatar for agmolina90

Ok I am a programming student and need help with a problem, I already have most of it (so I don't need you guys to do my hw :P) but I am having problems with am, and I am not even sure if I am doing it right. [B]Problem:[/B] (The …

Member Avatar for Ezzaral
-1
10K
Member Avatar for lacoffo

Hey all:) I'm learning Java and I'm having a little trouble on a polymorphic write-to-file function. Let me quickly explain my project: I have an abstract class Mammal, with non-abstract children Horse, Cow etc. I have a Main program that creates a couple Horses and Cows, and store these in …

Member Avatar for lacoffo
0
255
Member Avatar for Rimojenkins

Hello. I'm currently making a program that deals with a priorityQueue and inheritence/polymorphism. Student -> undergrad -> coop_student or student -> grad Now, the queue takes in the data and just puts it in a linked list and gives it a priority. That way, there are 3 queues and we …

Member Avatar for LevyDee
0
261
Member Avatar for zaneulhaq

Hey guys i'll show the code first then explain my problem: [code=c] Class A { /*Variables required by A, B, C and D */ /*functions required by B and C*/ }; Class B { /*some of it's own functions and variables*/ }; Class C { /*some of it's own functions …

Member Avatar for Stefano Mtangoo
0
386
Member Avatar for manish250

Hello all I have a query,may be silly but i have to clear it.IT IS REGARDING THE UPCASTING.I want to "when we can invoke the methods of base class using the object of derived class.then what is the need of assigning the subclass object to base class reference." I mean …

Member Avatar for JamesCherrill
0
148
Member Avatar for emcyroyale

Basically this program uses an abstract class which 3 other classes extends to so that in the end an overridden toString() method will print out how many pages must be read for each class. Okay, well this program is for a class, but I am kinda of stuck because my …

Member Avatar for quuba
0
202
Member Avatar for gilly231

I need help with an assignment for my programming course. I have three classes A,B,C. all stored in one array. (These are not my real classes there are just a guide) [CODE=c] Class A{ char name; public: virtual print(){ printf("%s",name); } } Class B : public A{ char middleName; public: …

Member Avatar for gilly231
0
191
Member Avatar for lytnus

I have a design question which I have not been able to find a satisfactory answer for by searching. Essentially, I have a class - Base - that contains a vector of pointers to another class - Node. However, I would like to be able extend both the Base and …

Member Avatar for lytnus
0
275
Member Avatar for maddav

Hi, just a quick question (i hope!!), i'm working on an assignment where i need to build a user-defined library of shapes. The class structure is to have "shape" as a base-class with both 2d and 3d shapes as derived classes. I've handled this by storing them in a vector …

Member Avatar for maddav
0
616
Member Avatar for metdos

Hello Everyone, I'm trying to implement a Polymorphic Queue. Here is my trial: [CODE]QQueue <Request *> requests; while(...) { QString line = QString::fromUtf8(client->readLine()).trimmed(); if(...)){ Request *request=new Request(); request->tcpMessage=line.toUtf8(); request->decodeFromTcpMessage(); //this initialize variables in request using tcpMessage if(request->requestType==REQUEST_LOGIN){ LoginRequest loginRequest; request=&loginRequest; request->tcpMessage=line.toUtf8(); request->decodeFromTcpMessage(); requests.enqueue(request); } //Here pointers in "requests" do not …

Member Avatar for metdos
0
280
Member Avatar for o0mkh0o

Hello! Im having a problem with the following code structure. The code compiles without problems but when i start the program i get an "exception: __non_rtti_object at memory location...". In the constructor of the model-class i still can get the object information of the node-class through the base pointer. Once …

Member Avatar for o0mkh0o
0
320

The End.