MCQ Practice Single Best Answer Topic: Overriding and Overloading in Java

Q 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.pr                

Question ID
#2240
Subchapter
Overriding and Overloading in Java
Action
Choose one option below

Choose Your Answer

Click an option to check whether your answer is correct.

  • A 10
  • B 20
  • C 30
  • D 40
Correct Answer: D

Explanation

40

Share This Question

Share this MCQ with your friends or study group.