Q2:(4 Points) if we have the following two classes defined class Matrix ( int m-
ID: 3874668 • Letter: Q
Question
Q2:(4 Points) if we have the following two classes defined class Matrix ( int m-0 public Matrix) (m-s public void jump(O System.out.printin(jumpm) public void punchO m--i System.out.printin("punch"+m) public class Agent extends Matrix int a-2 public Agent() { a=0; } public void gesture) ( a++i System.out.println ("glare" a): public void punch () gesture (); a--i system.out.println("pow!"+ a)i Then what is the output, if we execute the following main method public static void main(Stringll args) Matrix one new Agent ); one.punch ) Agent two new Agent i two.punch ():Explanation / Answer
The program will give the output as
glare1
pow!0
glare1
pow!0
Because the class Agent overrides method punch, so when one.punch is called it will invoke punch from Agent class thogh one is created from Matrix class.
Object two is directly defined from Agent class so, it will call method of Agent class.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.