Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 9: Inheritance
Start Practice TestPractice Test
About Exam
medium Solved by 2 students

Inheritance and Static Variables

Mark
< Prev
Next >

Consider the following class declarations.

public class Parent {
   public static int value = 10;
}

public class Child extends Parent {
   public static int value = 20;
   public void printValues() {
       System.out.println("Child: " + value);
       System.out.println("Parent: " + super.value);
   }
}

public class Main {
   public static void main(String[] args) {
       new Child().printValues();
   }
}

What is printed when the main method of the Main class is executed?

A

Child: 10
Parent: 20

B

Child: 10
Parent: 10

C

Child: 20
Parent: 10

D

Child: 20
Parent: 20

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|