Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. Class X defines method M1( ) as abstract. Class Y inherits from Class X and i

ID: 3657354 • Letter: 3

Question

3. Class X defines method M1( ) as abstract. Class Y inherits from Class X and implements the method M1( ). Given the following code, explain why a reference to the abstract class X is allowed to refer to an object of the concrete class Y. Explain what happens when the reference to the abstract class X is used to execute method M1( ). X obj = new Y( ); obj.M1( ); 5. Define a simple interface named Motorized with one method (maxSpeed) which returns the maximum attainable speed and another method (fuelType) which returns the type of fuel required. 6. Given the interface defined in question 5, if a class named Motorcycle implements this interface, explain why the following code is legal. What happens when the interface reference vehicle invokes the maxSpeed method? Motorized vehicle = new Motorcycle( ); System.out.print(

Explanation / Answer

Explain what happens when the reference to the abstract class X is used to execute method M1( ). X obj = new Y( ); here we are creating the object of Y using base class X obj.M1( ); calling above method calls M1 from derived class Y.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote