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
Get step-by-step solutions from verified subject matter experts
