Object Oriented Programming java Model Exam
1. Which of the following is NOT a feature of Object-Oriented Programming?
(A) Inheritance
(B) Encapsulation
(C) Polymorphism
(D) Compilation
2. In Java, objects are instances of __________.
(A) Classes
(B) Interfaces
(C) Packages
(D) Methods
3. Which of the following keywords is used to create an object in Java?
(A) new
(B) class
(C) void
(D) this
4. What is the process of creating a new instance of a class called in Java?
(A) Inheritance
(B) Abstraction
(C) Encapsulation
(D) Instantiation
5. Which of the following is NOT an access modifier in Java?
(A) public
(B) private
(C) protected
(D) static
6. What is the purpose of the "this" keyword in Java?
(A) To create a new object
(B) To access static members of a class
(C) To refer to the current object
(D) To call a superclass constructor
7. What is the output of the following code snippet in Java?
class MyClass
{
int x = 5;
void printValue()
{
int x = 10;
System.out.println("Value: " + x);
}
}
public class Main {
public static void main(String[] args) {
MyClass obj = new MyClass();
obj.printValue();
}
}
(A) Value: 5
(B) Value: 10
(C) Compilation error
(D) Runtime error
8. In Java, a class can inherit from __________.
(A) Multiple classes
(B) One class only
(C) Interfaces only
(D) Both interfaces and classes
9. What is the purpose of the "super" keyword in Java?
(A) To create a new object
(B) To access static members of a class
(C) To refer to the superclass
(D) To call a subclass constructor
10. Which of the following is NOT a principle of Object-Oriented Programming?
(A) Abstraction
(B) Encapsulation
(C) Polymorphism
(D) Algorithm
11. What is the output of the following code snippet in Java?
class Shape {
void draw() {
System.out.println("Drawing a shape");
}
}
class Circle extends Shape {
void draw() {
System.out.println("Drawing a circle");
}
}
public class Main {
public static void main(String[] args) {
Shape shape = new Circle();
shape.draw();
}
}
(A) Drawing a shape
(B) Drawing a circle
(C) Compilation error
(D) Runtime error
12. Which of the following is an example of a Java interface?
(A) if-else
(B) for loop
(C) switch-case
(D) Runnable
13. What is the keyword used to implement inheritance in Java?
(A) extends
(B) implements
(C) inherits
(D) derives
14. What is the purpose of the "abstract" keyword in Java?
(A) To create an object
(B) To define a class that cannot be instantiated
(C) To access static members of a class
(D) To refer to the current object
15. Which of the following is NOT a type of inheritance in Java?
(A) Single inheritance
(B) Multiple inheritance
(C) Multilevel inheritance
(D) Hierarchical inheritance
16. What is the output of the following code snippet in Java?
public class Main {
static int x = 10;
public static void main(String[] args) {
int x = 5;
System.out.println(x);
}
}
(A) 10
(B) 5
(C) Compilation error
(D) Runtime error
17. Which of the following is true about method overloading in Java?
(A) Methods must have the same name and the same number of parameters.
(B) Methods must have the same name but different return types.
(C) Methods must have the same name but different parameter types or a different number of
parameters.
(D) Methods must have the same name, parameter types, and return type.
18. What is the output of the following code snippet in Java?
class A {
void display() {
System.out.println("Class A");
}
}
class B extends A {
void display() {
System.out.println("Class B");
}
}
class C extends B {
void display() {
System.out.println("Class C");
}
}
public class Main {
public static void main(String[] args) {
A obj = new C();
obj.display();
}
}
(A) Class A
(B) Class B
(C) Class C
(D) Compilation error
19. What is the purpose of method overriding in Java?
(A) To create multiple methods with the same name but different parameter types or a different
number of parameters.
(B) To create a new class from an existing class.
(C) To define methods inside an interface.
(D) To provide a different implementation of a method in a subclass.
20. What is the output of the following code snippet in Java?
class A {
static void display() {
System.out.println("Class A");
}
}
class B extends A {
static void display() {
System.out.println("Class B");
}}
public class Main {
public static void main(String[] args) {
A obj = new B();
obj.display();
}
}
(A) Class A
(B) Class B
(C) Compilation error
(D) Runtime error
21. What is the purpose of the "final" keyword in Java?
(A) To create a new object
(B) To access static members of a class
(C) To define a class that cannot be inherited or overridden
(D) To refer to the superclass
22. What is the output of the following code snippet in Java?
class A {
A() {
System.out.println("Class A");
}
}
class B extends A {
B() {
System.out.println("Class B");
}
}
public class Main {
public static void main(String[] args) {
B obj = new B();
}
}
(A) Class A
(B) Class B
(C) Class A
(D) Compilation error
23. Which of the following is an example of runtime polymorphism in Java?
(A) Method overloading
(B) Method overriding
(C) Class inheritance
(D) Object instantiation
24. What is the output of the following code snippet in Java?
interface MyInterface {
void display();
}
class MyClass implements MyInterface {
public void display() {
System.out.println("Displaying");
}
}
public class Main {
public static void main(String[] args) {
MyInterface obj = new MyClass();
obj.display();
}
}
(A) Displaying
(B) Compilation error
(C) Runtime error
(D) No output
25. Which of the following is an object encapsulated inside the System class?
(A) out
(B) println
(C) Both A and B
(D) None of the above
26. Which of the following is not a primitive data type in Java?
(A) int
(B) float
(C) double
(D) string
27. Which of the following is not a keyword in Java?
(A) final
(B) static
(C) private
(D) namespace
28. Which of the following is a reserved word in Java?
(A) goto
(B) const
(C) virtual
(D) friend
29. Which of the following is not a valid identifier in Java?
(A) _myVar
(B) myVar
(C) 1myVar
(D) $myVar
30. Which of the following is not a valid access specifier in Java?
(A) public
(B) private
(C) protected
(D) internal
31. Which of the following is not a valid modifier in Java?
(A) final
(B) static
(C) abstract
(D) virtual
32. Which of the following is not a valid loop in Java?
(A) for
(B) while
(C) do-while
(D) repeat-until
33. What is the result of the expression: 10+5*8-15/5
(A) 3
(B) 47
(C) 7
(D) 21
34. Which statement is Java’s multi-way branch statement?
(A) switch
(B) nested if
(C) break
(D) if-else-if ladder
35. Which loop always executes its body at least once, even though the condition is not true?
(A) for
(B) do-while
(C) while
(D) continue
36. Which of the following is a type of variable in Java?
(A) Local variable
(B) Instance variable
(C) Class variable
(D) All of these
37. What will be the output of the following Java code?
public class Main {
public static void main(String[] args) {
String str = "Hello";
str = "Bye";
System.out.println(str);
}
}
(A) Hello
(B) Bye
(C) Compilation error
(D) Runtime error