I know you can create nested classed (or just classes declared outside of the class in the same file) but what is the point of doing this? Why not just create a new class file?

Member Avatar
Member Avatar
+0 forum 3

I am working on a project in BlueJ which I have to add an "Event Post" to a simple social network project. I have created the project but I am unsure how to take a string, such as "message", from a subclass of the Class Post and print it the post is a message post. If it is an event post, I need to print a string for the description of the event and then a string of the time. Here is the code that prints out the information about a post in the Post class: /** * Display the …

Member Avatar
Member Avatar
+0 forum 2

Please bear with me, this is my first post So, I have this superclass called A. And I've 2 subclasses A1 and A2. A has attribute name. A has function toString(). A1 inherits name, and has attribute hair. A1 has a method toString() which goes: string A1::toString(){ string stringA= A::toString(); stringstream info; info<<stringA<<" "<<hair; return info.str(); } A2 is the same as A1, except that it has face instead of hair. it's toString goes info<<stringA<<" "<<face; In my main(), vector<A*> vector; Then, I have a function to add objects void addA1 (vector<A*> &vector) void addA2 (vector<A*> &vector) both use push_back, …

Member Avatar
Member Avatar
+0 forum 2

<? 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 extends Animal{ public static void main(String r[]) { List l1 = new ArrayList(); //can add anything since no type here l1.add(new Dog()); l1.add(new Animal()); l1.add(30); met(l1); System.out.println(l1); } public static void met(List<? super Animal> l2) { l2.add(new Animal()); l2.add(new Dog()); System.out.println(l2); }} Even with Generic Instantiation(shown below) same output!! This …

Member Avatar
Member Avatar
+0 forum 11

General rules is that: 1) A private method cannot be overridden. 2) Subclass method should be a lower access modifier than a overridden superclass method. But the output of the program is "I am Son". Why? Is it because of the rule 2 the output comes? If that's the case here, then two rules of overriding I mentioned above are clashing, aren't they? Help please. Thanks.

Member Avatar
Member Avatar
+0 forum 8

Hey, following Problem: I have two classes Measurement and its subclass DC_Measurement. Measurement has a method called: [CODE]public virtual SetPoint[,] createSetPointArray()[/CODE] DC_Measurement: [CODE]public override DCSetPoint[,] createSetPointArray()[/CODE] DCSetPoint is also a subclass of SetPoint. I read that this is possible. Now I use in my mainWindow following code which contains an error: [CODE] DCSetPoint[,] calArray = selectedMeasurement.createSetPointArray(); [/CODE] Error: Cannot implicitly convert type 'paMeasure.SetPoint[*,*]' to 'paMeasure.DCSetPoint[*,*]'. An explicit conversion exists (are you missing a cast?) I don't know what to do. Thanks for help.

Member Avatar
Member Avatar
+0 forum 1

How can i run my Subclass where my GUI code are written from my Main Class?What codes should i write in my main class??Here are my codes: Main Class: my main class is blank because i really dont know what to write. [CODE] */ package classpkg; /** * * @author kishishi */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here } } [/CODE] here is the SubClass: [CODE] package classpkg; import java.awt.*; import javax.swing.JButton; import javax.swing.JFrame; public class GridBagLayoutDemo { final static boolean …

Member Avatar
Member Avatar
+0 forum 1

My images contained inside a tags have blue borders around them. How do I get rid of these borders? Here's what I've been trying and it doesn't work: [CODE]#gallery .a .img { border-style: none; }[/CODE]

Member Avatar
Member Avatar
+0 forum 2

Hi there. I am currently trying to get my head around using classes across two files. I currently have a super class and a sub class stored in a file and the main function in another. When I try and pass arguments to the class they work fine if the values are int's. However, what I want to pass are book names. Here is the code. [CODE]//publication.cpp #include <iostream> #include <string> using namespace std; //the publication super class class publication { private: char title; //the title of the book char genre; //the genre of the book double date; //the date …

Member Avatar
Member Avatar
+0 forum 3

I am wanting to reference an object of type JTextField and convert it to JFormattedTextField. Is it possible to convert to a subclass? I tried coding something to the affect of [CODE]ClassA.object = new JFormattedTextField(); ClassA.object.setValue(new Integer(number)); [/CODE] But no success. Any suggestions?

Member Avatar
Member Avatar
+0 forum 3

I just wanted to demonstrate a quick point regarding Constructors & inheritance. Look at these two classes and think about what you might expect to see after the main method has run. Notice that ClassB is a subclass (inherits from) of ClassA. So, what do we expect the output to be? Here's the output: run: Class A constructor Class B constructor BUILD SUCCESSFUL (total time: 0 seconds) As you can see, the main method makes an explicit call to ClassB's constructor, but not ClassA's constructor. ClassA's constructor, is, however called implicitly because ClassB is a subclass of ClassA. An important …

Member Avatar
Member Avatar
+3 forum 6

Hi everyone I have system that has classes derived from QGraphicsWidget. I manage derived class objects in layouts on QGraphicsScene. Now I need a compound item that contain two or more QGraphicsWidget in it and also I need to put that item inside my layout. So I choose QGraphicsItemGroup and write I class like this. [CODE]class CompositeItem : public QGraphicsItemGroup,public QGraphicsLayoutItem { ... };[/CODE] I only implemented sizeHint function again. When add CompositeItem instance to layout it does not shown. What may cause this? Where I made wrong?

Member Avatar
Member Avatar
+0 forum 5

Good evening Daniweb, I have another idiotic problem which comes from making an arrival subclass out of Event. I have a few other subclasses of Event and they aren't giving me any trouble. I have tried to copy/paste/rewrite to eliminate any stupid typos. Arrival.h:7: error: expected class-name before ‘{’ token [CODE=CPP] #ifndef ARRIVAL_H #define ARRIVAL_H #include "Event.h" using namespace std; class Train; class Arrival : public Event{ public: Arrival(int time, Train* newTrain); void print(); void activate(); ~Arrival(); }; #endif [/CODE]

Member Avatar
Member Avatar
+0 forum 9

i everybody, I am required to find out if the following is a standard practice to create a subclass. Take for instance, I have to create a class library (ClLib) with 2 classes using Visual Studio: Class1.cs &amp; Class2.cs. Next, I open up the .CSPROJ file of ClLib and modify the following line: [CODE]<Compile Include="Class2.cs" />[/CODE] to become [CODE]<Compile Include="Class2.cs" > <DependentUpon> Class1.cs </DependentUpon>[/CODE] Can any kind soul help me solve this question? Your help would be greatly appreciated!

Member Avatar
Member Avatar
+0 forum 8

Hello folks I'm trying to do my assignment and I'm really stuck in! I have to classes..Customer and Pensioner (Customer = Super class and Pensioner = Subclass) The Pensioner has a PensionNo extra than Customer class. I have to make a array of Customer class (for 10) and put Customer and Pensioner in it. Then I have to override << operator and print out the values of Customer/Pensioner in a file. Customer.h [CODE] #ifndef CUSTOMER_H #define CUSTOMER_H #include <iostream> #include <fstream> #include <string> using namespace std; class Customer { public: Customer(string _firstname, string _lastname, string _telephone, int _noofcall); friend ostream& …

Member Avatar
Member Avatar
+3 forum 8

The End.