| | |
Class in a class...
![]() |
•
•
Join Date: Mar 2005
Posts: 30
Reputation:
Solved Threads: 0
Hello everyone,
I have two classes Student and Courses. Class Students creates an object of class Courses since each Student will take some Courses.
How can I call an object of class Courses in class Students such that each Student class will have an instance of class Courses which will take care of setting , getting and printing course details for each students.
Also, how can I use inputs from console to initialize Students created. i.e., prompt user for input and use the set methods of the objects to take the console inputs to initialize the Student created.
Thank you in anticipation of your response.
Crestaldin
I have two classes Student and Courses. Class Students creates an object of class Courses since each Student will take some Courses.
How can I call an object of class Courses in class Students such that each Student class will have an instance of class Courses which will take care of setting , getting and printing course details for each students.
Also, how can I use inputs from console to initialize Students created. i.e., prompt user for input and use the set methods of the objects to take the console inputs to initialize the Student created.
Thank you in anticipation of your response.
Crestaldin
sorry for the anglosaxon community, but this is (best in) dutch...
niet zo flauw, wenting!
alle begin is moeilijk...
peter
p.s. is er geen boekje zoals 'java in 10 minuten' in het engels, daar is het (java) voor mij mee begonnen, één van de voorbeeldjes is inmiddels uitgegroeid tot een programma van (net geen) 10000.
regels in 2 1/2 jaar.
hobby???
cu
peter
niet zo flauw, wenting!
alle begin is moeilijk...
peter
p.s. is er geen boekje zoals 'java in 10 minuten' in het engels, daar is het (java) voor mij mee begonnen, één van de voorbeeldjes is inmiddels uitgegroeid tot een programma van (net geen) 10000.
regels in 2 1/2 jaar.
hobby???
cu
peter
Last edited by p.bondam; Nov 19th, 2006 at 3:01 pm. Reason: forgot that the daniweb language is english...
maybe later
•
•
Join Date: Nov 2006
Posts: 4
Reputation:
Solved Threads: 1
I really dont understand the need of creating a class within another class..
The logic there seems to be pretty cluttered.
Instead, there should be 2 separate classes which make things simple for further modifications.
Also, delegations are a better way of object orientated programming.
The student class can be aware of the courses class where as the course is completely unaware of the existance of a student class.. I think printing details would also be easier in this case..
The logic there seems to be pretty cluttered.
Instead, there should be 2 separate classes which make things simple for further modifications.
Also, delegations are a better way of object orientated programming.
The student class can be aware of the courses class where as the course is completely unaware of the existance of a student class.. I think printing details would also be easier in this case..
•
•
•
•
Hello everyone,
I have two classes Student and Courses. Class Students creates an object of class Courses since each Student will take some Courses.
How can I call an object of class Courses in class Students such that each Student class will have an instance of class Courses which will take care of setting , getting and printing course details for each students.
Also, how can I use inputs from console to initialize Students created. i.e., prompt user for input and use the set methods of the objects to take the console inputs to initialize the Student created.
Thank you in anticipation of your response.
Crestaldin
He doesn't seem to grok the concept of having members in a class that aren't primitives, he's not looking at nested or inner classes at all (though his topic does suggest so).
Yet any basic tutorial (and certainly his teacher) will handle that in the first few lessons...
It's therefore obvious that he needs to pay more attention in class, or he'd not have needed to ask this question, as it will have been handled already (and his course material will also handle it, if he but reads it).
Yet any basic tutorial (and certainly his teacher) will handle that in the first few lessons...
It's therefore obvious that he needs to pay more attention in class, or he'd not have needed to ask this question, as it will have been handled already (and his course material will also handle it, if he but reads it).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
•
•
Join Date: Mar 2004
Posts: 763
Reputation:
Solved Threads: 38
I'll give him the simple answer to the first part simply because he typed his question like an adult and not some kid using a bunch of net lingo shortcuts.
Java Syntax (Toggle Plain Text)
public class Student { private Courses courses = new Courses(); //constructor public Student() { } }
![]() |
Similar Threads
- Copy constructor in derived class (C)
- Java Class Class problem (Java)
- 6 Line class -> Me pounding head into wall (C)
- Bank account class (C++)
- Derived class problem (C)
- Class Passing and Returning Arrays (Java)
Other Threads in the Java Forum
- Previous Thread: Adding mouse listener to a frame
- Next Thread: I need an Explanation of Recursion...
| Thread Tools | Search this Thread |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card class client code collision component crashcourse css csv database eclipse ee error fractal free ftp game gis givemetehcodez graphics gui html ide image integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linked linux list loan machine map method methods migrate mobile netbeans objects oriented output phone physics printf problem program programming project projects radio recursion replaydirector reporting researchinmotion rotatetext scanner se server service set sms software sort sql string swing test textfield threads tree trolltech ubuntu utility windows






