Assume you need to write a class Racedog. It should be a sub-class of class Dog.
ID: 3883552 • Letter: A
Question
Assume you need to write a class Racedog. It should be a sub-class of class Dog.
Racedogs take part in dog races and they are very fast.
You want to override the method move of class Dog by printing the text it always printed (run) but you want to add " fast" (run fast)
In order to do that your implementation of the overridden move method calls the move method of the super-class.
Which of the following method calls of the super-class implementation is correct?
super.move();
_______________________________________________________
Assume you have a class Friend that is a sub-class of class Human.
You have two variables:
Friend boyA = new Friend("Mike");
Human boyB = new Human("Fritz");
Which of the following conditions checks whether boyB is a friend?
move.super();Explanation / Answer
super.move();
This method is used since super is a keyword which refers the super or parent class object or instance variable so super.move() method invokes the super class method.
(boyB instanceof Friend) condition checks if boyB is a type of Friend class or not which results in "False" .
instanceof operator returns true or false by checking whether a given object is a type of specified class or not.
boyB is an object of super class Human and Friend is a sub class of Human. So super class object boyB can not be type of sub class Friend so the condition (boyB instanceof Friend) returns False.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.