Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes super class question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "super class question" Watch "super class question" New topic

super class question

Glenn Jayasuriya

Joined: May 15, 2012
Posts: 4
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
Matthew Brown

Joined: Apr 06, 2010
Posts: 4541

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

Joined: May 15, 2012
Posts: 4
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
I agree. Here's the link:
subject: super class question
It's not a secret anymore!