🎴 Flashcard Mode

Programming in Java

Card1 / 10
Mastered0
Review0
QuestionClick to flip

What is the output of the following program?
import java.io.*;
class sample3
{
int a;
int b;
sample3()
{
a=0;
b=0;
}
sample3(int b1,int c1)
{
a=b1; b=c1;
}
final void print()
{
System.out.print(a);
System.out.print(b);
}
}
class sample31 extends sample3
{
int c;
sample31()
{
c=0;
}
sample31(int c)
{
this.c=c; super(4,5);
}
public static void main(String args[])
{
sample3 ob1=new sample3(4,5);
sample31 ob=new sample31();
System.out.print(ob.a);
System.out.print(ob.b);
System.out.print(ob.c);
sample31 ob2=new sample31(5);
System.out.print(ob2.a);
System.out.print(ob2.b);
System.out.print(ob2.c);
}

AnswerClick to flip back
A
Cannot call super class constructor
Call to the super must be first in the constructor.
💡 Explanation:

super(*) keyword should be the first line constructor, in which it is defined.

Change Mode