Results 1 to 5 of 5
Thread: is there a way for me to do this
- 02-12-2011, 06:49 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 24
- Rep Power
- 0
is there a way for me to do this
I have 3 student types and I want to create one "stud" depending on which type is sent. Is there a way to do this?
Java Code:private void addgrad(int t){ if (type == 1){ graduate stud = new graduate(); } if (type ==2){ partTime stud = new partTime(); } if (type == 3){ undgrad stud = new undgrad(); }
-
Sure, but perhaps you want to make your class return Student, and then return one of the type you've created, either that or throw an exception if the int is wrong.
- 02-12-2011, 07:54 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 24
- Rep Power
- 0
cool but how do i find out what type to return? it tells me its incompatible types
required java.util.list
found gradate
required java.util.list
found partTime
required java.util.list
found undgrad
- 02-12-2011, 07:57 PM #4
Member
- Join Date
- Jan 2011
- Posts
- 24
- Rep Power
- 0
never mind too quick with the question that time! Thanks
-


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks