Sail E0 Webinar
Question
What will be printed after executing following program code?
class Base{
int value = 0;
Base(){
addValue();
}
void addValue(){
value += 10;
}
int getValue(){
return value;
}
}
class Derived extends Base{
Derived(){
addValue();
}
void addValue(){
value += 20;
}
}
public class Test{
public static void main(String[] args){
Base b = new Derived();
System.out.println(b.getValue());
}
}
Options:
A .  30
B .  10
C .  40
D .  20
E .  None of these
Answer: Option C

Submit Your Solution Below and Earn Points !
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

More Questions on This Topic :


Latest Videos

Latest Test Papers