Wings 1 Java Spring MCQ
Wings 1 Java Spring MCQ
A) super
B) subclass
C) extends
D) implements
Answer: C) extends
Explanation: In Java, the extends keyword is used to indicate that a class is a subclass of
another class.
What is the output of the following Java code snippet?
java
class Parent {
void display() {
System.out.println("Parent's display method");
}
}
interface Animal {
void eat();
}
User
create 50 questions based on the above
ChatGPT
Creating 50 unique questions based on the provided concepts may lead to redundancy, so I'll
diversify the questions to cover a wide range of topics in Java and object-oriented programming
(OOP). Let's begin:
class Parent {
void display() {
System.out.println("Parent's display method");
}
}
interface Animal {
void eat();
}
class A {
void display() {
System.out.println("A's display method");
}
}
class B extends A {
void display() {
System.out.println("B's display method");
}
}
class C extends B {
void display() {
System.out.println("C's display method");
}
}
int x = 5;
int y = 2;
System.out.println(x / y);
A) 2
B) 2.5
C) 2.0
D) Compilation Error
Answer: A) 2
Which of the following is true about inheritance in Java?
A) A class can inherit from multiple classes.
B) Inheritance allows a subclass to access private members of its superclass.
C) Inheritance is a way to achieve code reusability and polymorphism.
D) Inheritance is not supported in Java.
Answer: C) Inheritance is a way to achieve code reusability and polymorphism.
What is the purpose of the interface keyword in Java?
A) It is used to declare a class as an interface.
B) It is used to define a class that cannot be instantiated.
C) It is used to define a blueprint of a class.
D) It is used to define a method that must be implemented by a class.
Answer: D) It is used to define a method that must be implemented by a class.
What is the output of the following Java code snippet?
java
int x = 5;
System.out.println(x++);
A) 4
B) 5
C) 6
D) Compilation Error
Answer: B) 5
Which of the following is true about the for-each loop in Java?
A) The for-each loop can only be used with arrays.
B) The for-each loop can only be used with collections.
C) The for-each loop guarantees the order of iteration.
D) The for-each loop uses an index variable to iterate.
Answer: C) The for-each loop guarantees the order of iteration.
What is the output of the following Java code snippet?
java
int x = 10;
if (x > 5) {
System.out.println("x is greater than 5");
} else {
System.out.println("x is less than or equal to 5");
}
A) x is greater than 5
B) x is less than 5
C) x is less than or equal to 5
D) Compilation Error
Answer: A) x is greater than 5
What is the output of the following Java code snippet?
java