0% found this document useful (0 votes)
6 views3 pages

Java Spring MCQs

The document contains multiple-choice questions (MCQs) related to Java and Spring Boot, focusing on object-oriented programming concepts such as inheritance, constructors, and abstract classes. Each question presents a code snippet and asks for the expected output or the correct answer regarding inheritance advantages. The questions test the understanding of Java's OOP principles and the behavior of classes and methods.

Uploaded by

hagerk720
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Java Spring MCQs

The document contains multiple-choice questions (MCQs) related to Java and Spring Boot, focusing on object-oriented programming concepts such as inheritance, constructors, and abstract classes. Each question presents a code snippet and asks for the expected output or the correct answer regarding inheritance advantages. The questions test the understanding of Java's OOP principles and the behavior of classes and methods.

Uploaded by

hagerk720
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Java and Spring Boot Coding MCQ

Questions
Java MCQ Questions (OOP & super keyword)
1. 1. class Animal {
void sound() {
System.out.println("Animal makes a sound");
}
}

class Dog extends Animal {


void sound() {
super.sound();
System.out.println("Dog barks");
}
}

public class Test {


public static void main(String[] args) {
Dog d = new Dog();
d.sound();
}
}

What is the output?

 A. Dog barks
 B. Animal makes a sound
 C. Animal makes a sound followed by Dog barks
 D. Compile-time error

2. 2. class A {
A() {
System.out.println("A's constructor");
}
}

class B extends A {
B() {
System.out.println("B's constructor");
}
}

public class Main {


public static void main(String[] args) {
B obj = new B();
}
}

What is the output?

 A. B's constructor
 B. A's constructor followed by B's constructor
 C. B's constructor followed by A's constructor
 D. Compile-time error

3. 3. class Parent {
int x = 10;
}

class Child extends Parent {


int x = 20;

void print() {
System.out.println(super.x);
}
}

public class Demo {


public static void main(String[] args) {
Child c = new Child();
c.print();
}
}

What is the output?

 A. 10
 B. 20
 C. Compile-time error
 D. 0

4. 4. Which is not an advantage of inheritance?

 A. Code reusability
 B. Runtime polymorphism
 C. Reduces redundancy
 D. Increases coupling between classes

5. 5. abstract class Shape {


abstract void draw();
}

class Circle extends Shape {


void draw() {
System.out.println("Drawing Circle");
}
}

public class Main {


public static void main(String[] args) {
Shape s = new Circle();
s.draw();
}
}

What is the output?

 A. Drawing Shape
 B. Drawing Circle
 C. Compile-time error
 D. Runtime error

You might also like