Here are 10 essential multiple-choice questions on Java Classes and Objects, covering key concepts.
Question 5
What will be the output of the following code?
class Test {
int x;
}
public class Main {
public static void main(String[] args) {
Test t = new Test();
System.out.println(t.x);
}
}
Question 7
What will be the output of the following code?
class Car {
String model;
}
public class Main {
public static void main(String[] args) {
Car c = null;
System.out.println(c.model);
}
}
Question 9
What will be the output of the following code?
class Example {
Example() {
System.out.println("Constructor called");
}
}
public class Main {
public static void main(String[] args) {
Example e = new Example();
}
}
There are 10 questions to complete.
Quiz about Java Classes and Objects