Single Choice Not Set

QWhat will be the result of compiling and running the given code?
class A{
      int b=10;
      private A(){
            this.b=7;
      }
      int f(){
            return b;
      }
}
class B extends A{
      int b;
}
public class Test{
      public static void main(String[] args){
            A a = new B();
            System.out.println(a.f());
      }
}

ID: #2268 Inheritance in Java MCQ 1,346 views
Question Info
#2268Q ID
Not SetDifficulty
Inheritance in Java MCQTopic

Choose the Best Option

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

  • A Compilation Fails ✔ ✖
  • B Prints 0 ✔ ✖
  • C Prints 10 ✔ ✖
  • D Prints 7 ✔ ✖
Correct Answer

Explanation

Compilation Fails
Today: 0 answered · 0 correct
Save progress
Free account

Want to remember what you got wrong?

Create a free account in seconds to track your score, revisit mistakes and continue Programming Language where you left off.

  • Save your progress & streak
  • Topic-wise quizzes & scores
  • Bookmark tricky questions
  • Printable MCQ sets
Practice smarterFree account · save progress
Sign up free

Share This Question

Challenge a friend or share with your study group.