Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

super class question

 
Glenn Jayasuriya
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I'm learning about super class.
I am having some problems.
Basically I am asked to determine whether an object of a super class array is of type of subclass.
However i can't use instanceof or getClass.
So i was thinking of using booleans.
So i made a boolean in the subclass that i want and set that to true.
Now i'm trying to pass this new boolean to the superclass however i get this error message: cannot reference grad before supertype constructor has been called
I changed the super class parameters to include the new boolean. However i still get this message.
Please help
Thanks
 
Matthew Brown
Bartender
Posts: 4565
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're probably going to have to show us the code.

However, the obvious question is why can't you use instanceof? Because that's what it's for.
 
Glenn Jayasuriya
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know instanceOf is what it's for but i was told not to use it.
Here is my code:

basically when i use the printGradStudent() method it should print out only the grad students. However to do this it must be able to differentiate which is a grad student and which is a undergrad student.
The method is not completed yet b/c i had to change it or it wouldn't compile.
I was thiniking of justing making a boolean variable in printGradStudent() and send that to super class (Student) in order to determine if the object is of type GraduateStudent
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic