Explore topic-wise MCQs in Java Programming.

This section includes 5 Mcqs, each offering curated multiple-choice questions to sharpen your Java Programming knowledge and support exam preparation. Choose a topic below to get started.

1.

What is the output of this program?

class N
{
int K;
void display()
{
System.out.println(K);
}
}
class M extends N
{
int L;
void display()
{
System.out.println(L);
}
}
public class MethodOverriding
{
public static void main(String args[])
{
M object = new M();
object.K=6;
object.L=5;
object.display();
}
}

A. 6
B. 5
C. Compilation Error
D. Runtime Error
E. None of these
Answer» C. Compilation Error
2.

What is the output of this program?

class N
{
public int K;
protected int L;
}
class M extends N
{
int L;
void display()
{
super.L = 5;
System.out.println(K + " " + L);
}
}
public class Result
{
public static void main(String args[])
{
M object = new M();
object.K=3;
object.L=4;
object.display();
}
}

A. 1 2
B. 2 3
C. 3 4
D. 4 5
E. 5 6
Answer» D. 4 5
3.

What is the output of this program?

class N
{
public int K;
public int L;
N()
{
K = 5;
L = 6;
}
}
class M extends N
{
int p;
M()
{
super();
}
}
public class super_Example
{
public static void main(String args[])
{
M object = new M();
System.out.println(object.K + " " + object.L);
}
}

A. 5 6
B. 6 5
C. Compilation Error
D. Runtime Error
E. None of these
Answer» B. 6 5
4.

What is the output of this program?

abstract class n
{
int K;
abstract void display();
}
class m extends n
{
int L;
void display()
{
System.out.println(L);
}
}
public class Abstract_class_Example
{
public static void main(String args[])
{
m obj = new m();
obj.L=5;
obj.display();
}
}

A. 1
B. 2
C. 3
D. 4
E. 5
Answer» F.
5.

What is the output of this program?

class N
{
public int K;
private int L;
}
class M extends N
{
void display()
{
super.K = super.L + 2;
System.out.println(super.K + " " + super.L);
}
}
public class inheritance_Example
{
public static void main(String args[])
{
M object = new M();
object.K=1;
object.L=2;
object.display();
}
}

A. 3 3
B. 4 4
C. Compilation Error
D. Runtime Error
E. None of these
Answer» D. Runtime Error