Results 1 to 5 of 5
  1. #1
    drgnfire25 is offline Member
    Join Date
    Jan 2011
    Posts
    24
    Rep Power
    0

    Default 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();
            }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  3. #3
    drgnfire25 is offline Member
    Join Date
    Jan 2011
    Posts
    24
    Rep Power
    0

    Default

    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

  4. #4
    drgnfire25 is offline Member
    Join Date
    Jan 2011
    Posts
    24
    Rep Power
    0

    Default

    never mind too quick with the question that time! Thanks

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •