Multiple choice

What is the output of the given program?

class A
{
int a;
A(int a)
{
System.out.println(a);
}
public void display()
{
System.out.println("Hello");
}
}
class ScopeTest extends A
{
public static void main(String[] args)
{
ScopeTest s1 = new ScopeTest();
s1.display();
}
}

  1. Hello

  2. 0

  3. Run time error

  4. Compilation error

  5. Blank output screen

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

This is the correct choice. Class ScopeTest extends class A. When we create an object of class ScopeTest, it automatically calls the non-argument constructor of class A, but there is no such constructor in class A. So, the compiler will throw an error. If we add a non-argument constructor (as shown below) in class A, then the code will compile.A(){} So, this answer is true.