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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started