MCQ Single Best Answer Not Set

QWhat 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());
	}
}

ID: #2259 Inheritance in Java MCQ 2,276 views
Question Info
#2259Q ID
Not SetDifficulty
Inheritance in Java MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A 30
  • B 10
  • C 40
  • D None of these
Correct Answer: Option C

Explanation

40

Share This Question

Challenge a friend or share with your study group.