Question: Given the following Java code, what method m will be executed when b.m() is executed.. class A { void m() {..} } class B extends

Given the following Java code, what method m will be executed when b.m() is executed.. class A { void m() {..} } class B extends A {void m() {..} } class Client { public static void main (String args[]) { A a = new A(); B b = new B(); b.m(); }}

a. Method m belonging to class B will be executed.

b.

Since B is a sub-class A, method m belonging to class B will be executed after method m belong to class A is executed. Super class methods are always executed first.

c.

Since B is a sub-class A, method m belonging to class A will be executed after method m belong to class B is executed. Sub class methods are always executed first.

d.

All other answers are wrong

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!