0% found this document useful (0 votes)
0 views

Java Object Concepts Quiz

The document contains a series of multiple-choice questions related to Java object concepts, including definitions of objects, classes, encapsulation, inheritance, constructors, method overloading, method overriding, polymorphism, interfaces, abstract classes, the 'this' keyword, static methods, and packages. It also includes questions about code outputs for specific Java snippets. Each question presents four answer options, with the correct answer indicated by the corresponding letter.

Uploaded by

louielaolong9
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)
0 views

Java Object Concepts Quiz

The document contains a series of multiple-choice questions related to Java object concepts, including definitions of objects, classes, encapsulation, inheritance, constructors, method overloading, method overriding, polymorphism, interfaces, abstract classes, the 'this' keyword, static methods, and packages. It also includes questions about code outputs for specific Java snippets. Each question presents four answer options, with the correct answer indicated by the corresponding letter.

Uploaded by

louielaolong9
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/ 7

Java Object Concepts Questions

1. **What is an object in Java?**

- A) A collection of variables

- B) An instance of a class

- C) A method

- D) A data type

2. **What is a class in Java?**

- A) A blueprint for creating objects

- B) A type of variable

- C) A method of an object

- D) None of the above

3. **What does encapsulation mean in Java?**

- A) Hiding the internal state of an object

- B) Creating multiple instances of a class

- C) Merging two classes

- D) None of the above

4. **What is inheritance in Java?**

- A) A way to define new classes based on existing ones

- B) A method for creating objects

- C) A technique for data hiding

- D) None of the above


5. **What is a constructor in Java?**

- A) A method that initializes an object

- B) A type of variable

- C) A way to create classes

- D) None of the above

6. **What is method overloading?**

- A) Defining multiple methods with the same name but different parameters

- B) Creating a method inside another method

- C) Overriding a method in a subclass

- D) None of the above

7. **What is method overriding?**

- A) Defining a method in a subclass that has the same name and parameters as a method in
the parent class

- B) Calling a method multiple times

- C) Creating a method with a different return type

- D) None of the above

8. **What is the purpose of the `super` keyword in Java?**

- A) To refer to the parent class

- B) To create a new object

- C) To call a method from the current class

- D) None of the above

9. **What is polymorphism in Java?**


- A) The ability to present the same interface for different underlying data types

- B) The process of creating multiple classes

- C) A way to hide data

- D) None of the above

10. **What is an interface in Java?**

- A) A contract that classes can implement

- B) A type of class

- C) A method of data hiding

- D) None of the above

11. **What is an abstract class in Java?**

- A) A class that cannot be instantiated and may contain abstract methods

- B) A class that can be instantiated

- C) A class with only static methods

- D) None of the above

12. **What does the `this` keyword refer to in Java?**

- A) The current object instance

- B) The parent class

- C) The main method

- D) None of the above

13. **What is a static method in Java?**

- A) A method that belongs to the class rather than any instance

- B) A method that cannot be overridden


- C) A method that can only be called once

- D) None of the above

14. **What is the difference between `==` and `.equals()` in Java?**

- A) `==` checks for reference equality, while `.equals()` checks for value equality

- B) Both do the same thing

- C) `.equals()` is used for primitive types only

- D) None of the above

15. **What is a package in Java?**

- A) A namespace that organizes a set of related classes and interfaces

- B) A way to hide data

- C) A method for creating objects

- D) None of the above


16. What will be printed by this code?

public class Main {

public static void main(String[] args) {

String[] fruits = {"Apple", "Banana", "Cherry"};

for (String fruit : fruits) {

System.out.print(fruit + " ");

A) Apple Banana Cherry


B) Apple, Banana, Cherry
C) "Apple" "Banana" "Cherry"
D) None of the above

17. What is the output of the following code?

public class Main {

public static void main(String[] args) {

int num = 7;

System.out.println(num % 2 == 0 ? "Even" : "Odd");

A) Even
B) Odd
C) 7
D) None of the above
18. What will be printed by the following code?

public class Main {

public static void main(String[] args) {

String str = "Java";

str = str.toUpperCase();

System.out.println(str);

A) Java
B) JAVA
C) "Java"
D) None of the above

19. What is the output of this program?

public class Main {

public static void main(String[] args) {

int x = 5;

x += 3;

System.out.println(x);

A) 5
B) 3
C) 8
D) None of the above
20. What will this code output?

public class Main {

public static void main(String[] args) {

int a = 10;

int b = 20;

System.out.println(a > b ? a : b);

A) 10
B) 20
C) a
D) None of the above

You might also like