wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Object Oriented Programming

Total questions: 65

Worksheet time: 27mins

Name
Class
Date
1.

After saving a Java source file named Calculator.java containing public class Calculator, what happens if you run javac Calc.java?

a)

It compiles successfully and creates Calculator.class

b)

It throws an error because Calc.java does not exist

c)

It runs but produces incorrect bytecode

d)

It renames the file automatically

2.

Which command correctly executes a compiled Java class named MainApp?

a)

java MainApp.class

b)

javac MainApp

c)

java MainApp

d)

javac MainApp.java MainApp

3.

Which condition correctly checks if a year is a leap year?

a)

(year % 4 == 0)

b)

(year % 100 == 0 || year % 400 == 0)

c)

(year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)

d)

(year % 400 == 0)

4.

Fibonacci series of 6 terms starting from 0, 1 is:

a)

0, 1, 1, 2, 3, 5

b)

1, 1, 2, 3, 5, 8

c)

0, 1, 2, 3, 5, 8

d)

0, 1, 1, 2, 4, 6

5.

Which operator is used to check divisibility in Java?

a)

%

b)

//

c)

&&

d)

==

6.

The formula for calculating simple interest in Java is:

a)

P * R * T / 100

b)

P + R + T

c)

P * R / T

d)

P / R * T

7.

Which loop correctly prints numbers 1 to 100?

a)

for(i=1;i<=100;i++)

b)

for(i=0;i<100;i--)

c)

while(i<=100;i++)

d)

do while(i<100)

8.

The factorial of 5 is:

a)

10

b)

60

c)

120

d)

720

9.

Palindrome check for string "madam" returns:

a)

Not Palindrome

b)

Palindrome

c)

Error

d)

madam

10.

Which one is NOT a correct vowel check in Java?

a)

if(c=='a')

b)

if(c=='e')

c)

if(c.equals('i'))

d)

if(c=='o')

11.

What is the Fahrenheit equivalent of 0°C?

a)

0

b)

32

c)

100

d)

212

12.

The average of 4, 6, and 8 is:

a)

5

b)

6

c)

7

d)

8

13.

The quotient of 15 / 4 is:

a)

3

b)

3.75

c)

4

d)

0

14.

15 % 4 resolve to ...

a)

1

b)

2

c)

3

d)

4

15.

The GCD of 20 and 28 is:

a)

2

b)

4

c)

6

d)

8

16.

The LCM of 4 and 6 is:

a)

12

b)

18

c)

20

d)

24

17.

Which of the following is an Armstrong number?

a)

123

b)

153

c)

370

d)

Both b and c

18.

Reversing the string "Java" gives:

a)

avaJ

b)

Java

c)

Jvaa

d)

aavJ

19.

How many tokens are in "I love Java"?

a)

2

b)

3

c)

4

d)

5

20.

Prime numbers between 1 and 10 are:

a)

2,3,5,7

b)

1,2,3,5,7

c)

2,4,6,8

d)

3,6,9

21.

The sum of the first 5 natural numbers is:

a)

10

b)

15

c)

20

d)

25

22.

The absolute value of -12 is:

a)

-12

b)

12

c)

0

d)

Error

23.

What happens if an array index goes out of range?

a)

Nothing

b)

Compilation error

c)

Runtime error

d)

Loops back

24.

The value of 2^5 computed without Math.pow is:

a)

10

b)

20

c)

25

d)

32

25.

The program checking if 29 is prime returns:

a)

True

b)

False

c)

Error

d)

0

26.

The factorial program output for 0! is:

a)

0

b)

1

c)

Undefined

d)

Error

27.

The program counting vowels in "education" gives:

a)

3

b)

4

c)

5

d)

6

28.

The program merging arrays {1,2} and {3,4} results in:

a)

{1,2,3,4}

b)

{3,4,1,2}

c)

{1,3,2,4}

d)

{2,1,4,3}

29.

A number divisible by both 3 and 5 will satisfy:

a)

num % 3 == 0 && num % 5 == 0

b)

num % 3 == 0 || num % 5 == 0

c)

num / 3 == 5

d)

num * 3 == 5

30.

When simulating a calculator, if input is 12 * 4, the output is:

a)

16

b)

36

c)

48

d)

124

31.
Java is considered both a compiled and interpreted language because:
a)
a) It is compiled to bytecode and then interpreted by the JVM at runtime.
b)
b) It is compiled to machine code for execution.
c)
c) It is interpreted line by line during compilation.
d)
d) It is compiled and executed directly by the operating system.
32.
Which of the following statements is true about constructors?
a)
a) They are used to initialize objects and have a return type.
b)
b) They can be inherited from a superclass.
c)
c) They can be overloaded like regular methods.
d)
d) They are called explicitly using the new keyword.
33.
How many times will "ADUSTECH" be printed to the console in the following program?
a)
a) 9
b)
b) 10
c)
c) 11
d)
d) 12
34.
What will be the output of the following statement? System.out.println("THE TIME IS " + 11 + 1 + " O CLOCK");
a)
a) THE TIME IS 111 O CLOCK
b)
b) THE TIME IS 12 O CLOCK
c)
c) THE TIME IS 11 1 O CLOCK
d)
d) THE TIME IS 112 O CLOCK
35.
The statement to receive the student's name from the keyboard using Scanner object “kybrd” and store it in the variable "name."
a)
a) String name = kybrd.readInput();
b)
b) String name = readLine();
c)
c) String name = kybrd.nextLine();
d)
d) String name = new Scanner(System.in).kybrd.nextLine();
36.
Which of the following is an example of a primitive data type in Java?
a)
a) String
b)
b) Integer
c)
c) Object
d)
d) Array
37.
What is the difference between local variables and instance variables?
a)
a) Local variables are declared within methods, and instance variables are declared within classes.
b)
b) Local variables are accessible throughout the class, and instance variables are only accessible within methods.
c)
c) Local variables have a default value, and instance variables must be initialized explicitly.
d)
d) Local variables are static, and instance variables are dynamic.
38.
Which Java statement displays the length of the string "Hello World."?
a)
a) System.out.println("Hello World".length());
b)
b) System.out.println(length("Hello World"));
c)
c) System.out.println(lengthOf("Hello World"));
d)
d) System.out.println("Hello World".size());
39.
What will be the output of the following code snippet? String text = "ADUSTECH"; System.out.println(text.toLowerCase());
a)
a) ADUSTECH
b)
b) ADUSTECH ()
c)
c) adustech
d)
d) ADUSTECH(adustech)
40.
The method "equalsIgnoreCase(String x)" is used to:
a)
a) Compare two strings while ignoring case differences.
b)
b) Concatenate two strings with ignoring case differences.
c)
c) Check if two strings are equal without considering their content.
d)
d) Extract a substring from the original string.
41.
What does the "charAt(int i)" method return?
a)
a) The character at index i in the string.
b)
b) The character at index i-1 in the string.
c)
c) The ASCII value of the character at index i.
d)
d) The index of the character i in the string.
42.
How do you extract the substring "ADUSTECH" from the string "WelcometoADUSTECH"?
a)
a) "Welcome to ADUSTECH".substring(9);
b)
b) "Welcome to ADUSTECH".substring(0, 8);
c)
c) "Welcome to ADUSTECH".substring(11);
d)
d) "Welcome to ADUSTECH".substring(11, 18);
43.
What will be the output of the following program?
a)
a) NESTED NESTED NESTED NESTED NESTED NESTED
b)
b) NESTED NESTED NESTED
c)
c) NESTED NESTED NESTED NESTED NESTED
d)
d) NESTED
44.
What does the term "class" refer to in object-oriented programming?
a)
a) A blueprint for creating objects.
b)
b) A function that defines the behavior of an object.
c)
c) A single instance of an object.
d)
d) A variable that holds object references.
45.
What is the purpose of a method in object-oriented programming?
a)
a) To create objects.
b)
b) To define the attributes of an object.
c)
c) To manipulate data in an object.
d)
d) To initialize the class variables.
46.
What is an array in Java?
a)
a) A data structure to store unrelated objects.
b)
b) A collection of elements of different data types.
c)
c) A collection of elements of the same data type.
d)
d) A special data type for numbers.
47.
Which of the following Java constructs is used for decision making?
a)
a) for loop
b)
b) switch statement
c)
c) try-catch block
d)
d) do-while loop
48.
What does the term "abstraction" mean in object-oriented programming?
a)
a) Hiding the implementation details and showing only the essential features.
b)
b) Using abstract classes to create objects.
c)
c) Creating classes without methods.
d)
d) Avoiding the use of interfaces in a program.
49.
What is the purpose of "encapsulation" in Java?
a)
a) To hide sensitive data from unauthorized access.
b)
b) To allow multiple classes to access the same data simultaneously.
c)
c) To store objects in a single file for easy transport.
d)
d) To prevent memory leaks in the program.
50.
What is "polymorphism" in object-oriented programming?
a)
a) The ability of a class to inherit from multiple parent classes.
b)
b) The ability to perform different actions based on the type of object.
c)
c) The process of converting an object into a different data type.
d)
d) The ability to create multiple objects from a single class.
51.
Which of the following statements is true regarding inheritance?
a)
a) A subclass can inherit from multiple parent classes in Java.
b)
b) A superclass can inherit from multiple subclasses in Java.
c)
c) Java doesn't support multiple inheritance.
d)
d) Inheritance is only applicable to interfaces, not classes.
52.
Which of the following is a key feature of Java that contributes to its portability?
a)
a) Bytecode and JVM
b)
b) Static typing
c)
c) Multiple inheritance
d)
d) Pointers
53.
What is the main advantage of using exception handling in Java?
a)
a) It allows the program to terminate immediately when an error occurs.
b)
b) It makes the program run faster by skipping error checks.
c)
c) It separates the normal flow of the program from error handling.
d)
d) It eliminates the need for if-else statements in the code.
54.
Which feature of Java allows multiple threads to execute concurrently?
a)
a) Garbage collection
b)
b) Exception handling
c)
c) Multi-threading
d)
d) Interface implementation
55.
Which feature of Java is responsible for preventing unauthorized access to class members?
a)
a) Inheritance
b)
b) Polymorphism
c)
c) Encapsulation
d)
d) Abstraction
56.
What is the purpose of the "final" keyword in Java?
a)
a) To indicate that a class cannot be extended.
b)
b) To indicate that a method cannot be overridden.
c)
c) To indicate that a variable's value cannot be changed.
d)
d) To indicate that a constructor cannot be called.
57.
Which of the following statements is true about an object in Java?
a)
a) An object is an instance of a class.
b)
b) An object is a type of data type.
c)
c) An object can exist without a class.
d)
d) An object can be directly created using the new keyword.
58.
When an object is created using the "new" keyword, which method is automatically called?
a)
a) initialize()
b)
b) construct()
c)
c) start()
d)
d) constructor()
59.
Which of the following is an example of method overloading in Java?
a)
a) Two methods with the same name and parameters in the same class.
b)
b) Two methods with the same name and different return types in the same class.
c)
c) Two methods with the same name and parameters in different classes.
d)
d) Two methods with the same name and the same parameters but different access modifiers in the same class.
60.
What is the role of the "this" keyword in Java?
a)
a) It refers to the current instance of the class.
b)
b) It is used to create a new object.
c)
c) It is used to call static methods.
d)
d) It is used to define a constructor.
61.
Which of the following statements is true about the default constructor in Java?
a)
a) It has parameters defined by the user.
b)
b) It is provided automatically by the compiler if no constructor is defined.
c)
c) It cannot be overloaded.
d)
d) It always has a return type.
62.
How do you declare a 2x3 integer array in Java?
a)
a) int[][] array = { {1, 2}, {3, 4}, {5, 6} };
b)
b) int[2][3] array = { {1, 2}, {3, 4}, {5, 6} };
c)
c) int[3][2] array = { {1, 2}, {3, 4}, {5, 6} };
d)
d) int array[2][3] = { {1, 2}, {3, 4}, {5, 6} };
63.
What is the relationship between a class and an array?
a)
a) An array is an instance of a class.
b)
b) A class is a collection of arrays.
c)
c) A class can have an array as an attribute.
d)
d) A class can inherit from an array.
64.
How do you access the second element in the third row of a 2D array named "matrix"?
a)
a) matrix[2][1]
b)
b) matrix[3][2]
c)
c) matrix[1][2]
d)
d) matrix[2][3]
65.
What is the purpose of the "length" attribute for an array in Java?
a)
a) It specifies the size of the array.
b)
b) It stores the sum of all elements in the array.
c)
c) It returns the total number of elements in the array.
d)
d) It is used to access the first element of the array.