0% found this document useful (0 votes)
13 views14 pages

OOP Questions

This document contains 20 questions and answers on fundamental concepts of object-oriented programming in Java, including method overloading, encapsulation, inheritance, polymorphism, and classes/interfaces.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views14 pages

OOP Questions

This document contains 20 questions and answers on fundamental concepts of object-oriented programming in Java, including method overloading, encapsulation, inheritance, polymorphism, and classes/interfaces.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Object-Oriented Programming (OOP) and Java:

What is method overloading in Java?

a. The possibility of having multiple methods with the same name in a class

b. The creation of a method in a subclass that has the same signature as a method of the
superclass

c. The use of multiple classes to create an object

d. The possibility of adding methods to an existing class

a. The possibility of having multiple methods with the same name in a class

How to access a class member (variable or method) from a non-static class


in Java?

a. Using the keyword 'this'

b. Using the keyword "static"

c. By using the 'new' operator

d. By using the 'instanceof' operator

Response: a. Using the keyword "this"

What is the main difference between a local variable and an instance variable in Java?

a. A local variable is declared inside a method, while an instance variable is


declared inside a class

b. A local variable is shared by all instances of a class, while a variable


of instance is not

c. The two terms are interchangeable, there is no difference.

d. A local variable can be used in any class, while a variable


the instance cannot do it

Answer: a. A local variable is declared inside a method, while a variable


an instance is declared inside a class

What is the main use of inheritance in object-oriented programming (OOP)?

a. Share code between multiple classes

b. Limiting access to certain methods

c. Make an abstract class

d. Create class instances

Answer: a. Share code between multiple classes

What do we call the process of converting an object into a sequence of bits for storage?
Where to send it?

a. Encapsulation

b. Serialization

c. Inheritance

d. Polymorphism

b. Serialization

What is the role of the keyword 'final' in front of a method in Java?

a. The method cannot be used in a Java program

b. The method cannot be modified after its declaration.

c. The method cannot be called


d. The method cannot be inherited

Response: b. The method cannot be modified after its declaration

What is a nested class in Java?

a class that cannot contain other classes

b. A class declared inside another class

c. A class that can be instantiated without creating an instance of the outer class

d. A class that cannot be instantiated

b. A class declared inside another class

How to access a static class member in Java?

a. By using the keyword 'this'

b. By creating an instance of the class

c. By using the class name followed by a dot

d. By using the 'new' operator

Answer: c. By using the class name followed by a dot

What is a checked exception in Java?

An exception that must be explicitly handled by the programmer

b. An exception that cannot be handled by the programmer.

c. An exception generated by a syntax error

An exception generated by a logic error in the program


a. An exception that must be explicitly handled by the programmer

What is polymorphism in Java?

a. The possibility of having multiple constructors in a class

b. The ability of a class to implement multiple interfaces

c. The ability of an object to take on different forms depending on its context

d. The use of multiple methods with the same name in a class

Response: c. The ability of an object to take different forms depending on its context

What is the main characteristic of object-oriented programming (OOP)?

a. Use of numerous loops

b. Structuring the code around objects

c. Total absence of methods

d. Exclusive use of global variables

b. Structuring the code around objects

What is an object in object-oriented programming (OOP)?

a conditional statement

An instance of a class containing data and methods

c. A primitive variable

a type of loop

b. An instance of a class containing data and methods


What is the correct syntax to create an instance of a class in Java?

a. new Object();

b. create Object();

c. Object.create();

d. Object.newInstance();

a. new Object();

What is the purpose of the keyword 'this' in Java?

a. Referencing the parent class

b. Referencing the current instance of the class

c. Declare a static variable

d. Initialize a variable

Response: b. Referencing the current instance of the class

What is the difference between a default constructor and a parameterized constructor in Java?

a. A default constructor does not accept any parameters, while a parameterized constructor does.
accept at least one

b. A default constructor accepts multiple parameters, whereas a parameterized constructor


accepts only one parameter

c. The two terms are interchangeable, there is no difference.

d. A default constructor cannot be used, whereas a parameterized constructor can.


the being

Answer: a. A default constructor accepts no parameters, while a constructor


configured to accept at least one

What is the meaning of the keyword 'extends' in Java?

a. Create a new instance of a class

b. Implement an interface

c. Extend the functionalities of an existing class

d. Declare an abstract class

Answer: c. Extend the functionalities of an existing class

How to declare a constant variable in Java?

a. Using the keyword 'constant'

b. Using the keyword 'readonly'

c. By using the keyword 'final'

d. By using the keyword 'immutable'

c. By using the keyword 'final'

What is the difference between a static method and a non-static (instance) method in Java?
?

a static method can be called without creating an instance of the class, while a
non-static method cannot

b. A static method cannot be modified, while a non-static method can be.

c. The two types of methods are identical

d. A non-static method can be called without creating an instance of the class, while a
static method cannot
a. A static method can be called without creating an instance of the class, while
that a non-static method cannot

What is the role of the garbage collector in Java?

a. Collect the waste and free the memory occupied by unreferenced objects

b. Manage the exceptions generated by the program

c. Compile the source code into bytecode

d. Handle syntax errors in the Java code

a. Collect the waste and free the memory occupied by unreferenced objects

What is the difference between a class and an interface in Java?

a. A class can contain concrete methods, while an interface cannot.

b. An interface can be instantiated, whereas a class cannot.

c. A class cannot contain variables, while an interface can.

d. An interface cannot contain abstract methods, whereas a class can.

Response: a. A class can contain concrete methods, while an interface cannot.

What is encapsulation in object-oriented programming (OOP)?

a. The ability of a class to inherit from multiple other classes

b. The grouping of data and methods into a single unit

c. The conversion of one class into another class

d. The use of multiple classes in a single program

Response: b. The grouping of data and methods into a single unit


What is the main difference between a class and an object in Java?

a. A class is an instance of an object

b. A class is a template for creating objects

c. An object is a global variable

d. An object is a method

b. A class is a blueprint for creating objects

What does the keyword 'static' in front of a method in Java mean?

a. The method can only be called once

b. The method belongs to the class rather than to a specific instance

c. The method can be called without creating an instance of the class

d. The method cannot be changed after its declaration.

Answer: c. The method can be called without creating an instance of the class

What is an interface in Java?

an abstract class

b. A concrete class

c. A set of abstract methods that classes must implement

d. A particular object

Answer: c. A set of abstract methods that classes must implement

In Java inheritance, what is the parent class called?


a. Superclass

b. Subclass

c. Derived class

d. Base class

a. Superclass

What is an abstract class in Java?

a class that cannot be instantiated

b. A class that can contain concrete methods

c. A class that cannot contain abstract methods

d. A class that cannot be extended (inherited)

a. A class that cannot be instantiated

How to define a 'has a' relationship between two classes in Java?

a. By using inheritance

b. Using composition

c. Using an interface

d. Using an abstract class

Response: b. By using composition

What is the difference between '==' and the equals() method in Java?

a. No difference, they do the same thing


"==" compares object references, while equals() compares the content of the objects

"==" compares the contents of the objects, while equals() compares the references.

"==" is used to compare primitive types, while equals() is used to compare


objects

b. '==' compares object references, while equals() compares the content of the objects

What is an exception in Java?

a type of class

A syntax error

c. An unforeseen event that occurs during the execution of the program

d. A static variable

Response: c. An unforeseen event that occurs during the execution of the program

What is a static inner class in Java?

a class that cannot be modified

b. A class that can be instantiated without creating an instance of the outer class.

c. A class that can only be modified by the outer class

d. A class that cannot contain methods

b. A class that can be instantiated without creating an instance of the outer class.

What is an object in object-oriented programming (OOP)?

a method

b. A global variable
c. An instance of a class

d. A for loop

Answer: c. An instance of a class

What is the fundamental principle of encapsulation in OOP?

a. Hide the internal implementation of an object and restrict access to its members

b. Allow an object to access the members of another object

c. Facilitate inheritance between multiple classes

d. Encapsulate all objects within a single class

a. Hide the internal implementation of an object and restrict access to its members

What is the difference between an abstract class and an interface in Java?

a. An abstract class can have concrete methods, whereas an interface cannot

b. An interface can have variable members, whereas an abstract class cannot.

c. The two are identical, there is no difference

d. An abstract class cannot have a constructor, whereas an interface can.

a. An abstract class can have concrete methods, whereas an interface cannot.


can't

What is polymorphism in OOP?

a. The possibility of having multiple constructors in a class

b. The ability of a class to implement multiple interfaces

c. The ability of an object to take different forms depending on its context


d. The use of multiple methods with the same name in a class

c. The ability of an object to take different forms depending on its context

In Java, what does the keyword 'final' used in front of a class mean?

a. The class cannot be extended (inherited)

b. The class cannot be instantiated

c. The class cannot contain final methods

d. The class cannot be used in a Java program

a. The class cannot be extended (inherited)

What is a constructor in Java?

a special method called when creating an object

b. A method used to destroy an object

c. A variable that stores the number of instances of a class

d. A special class used to create other classes

Response: a. A special method called when creating an object

What is the main difference between method overloading and method overriding in Java?

a. Overloading allows having multiple methods with the same name in a class, while the
method substitution does not allow it

b. Overloading occurs at compile time, while overriding occurs at


moment of execution

c. Overloading is a characteristic of inheritance, while substitution is a


characteristic of encapsulation
d. Overloading occurs when one method replaces another, while substitution
allows having multiple methods with the same name in a class

Response: d. Overloading occurs when one method replaces another, while the
Substitution allows having multiple methods with the same name in a class.

What does the keyword 'this' represent in Java?

a. The current class

b. The current instance of the class

c. The parent class

d. The child class

Answer: b. The current instance of the class

How would you declare a constant variable in Java?

a. By using the keyword 'constant'

b. Using the keyword 'readonly'

c. Using the keyword 'final'

d. By using the keyword 'immutable'

Answer: c. By using the keyword 'final'

What is the role of the garbage collector in Java?

a. Collect the waste and free the memory occupied by unreferenced objects

b. Manage the exceptions generated by the program

c. Compile the source code into bytecode


d. Manage syntax errors in the Java code

a. Collect the waste and free the memory occupied by unreferenced objects

You might also like