Student extend class
Person. Then, the way to test the lookup rules is to create an instance that looks like this:
Person x = new Student();
Then try the
toString method, to see which one it uses. It should use the
Student. But for everything else (static variables, static methods, instance variables), where both classes have one of the same name, it should use the one from
I believe what you describe in your original post is the inheritance rules. If a class does not contain an instance method that exists in
Object, java will work its way up the inheritance hierarchy, looking for the “lowest” version of the method to use.
Please try this out yourself. Do not take other people’s word for it. On the exam, we will be running the code from each of the questions to double-check our answers. Ultimately, if it works for you in IntelliJ, then it is correct.