Computer Knowledge
Object-Oriented Programming
2,686 Questions
Object-oriented programming questions test core computer science concepts like classes, inheritance, polymorphism, and encapsulation. The focus includes Java program structures, method overloading, and memory allocation for objects. This topic is essential for technical sections in various recruitment tests.
Java class definitionsMethod overriding rulesPolymorphism conceptsGeneric type parametersMemory allocation in objects
Object-Oriented Programming Questions
-
We can overload the main method in java.
-
We can override the static method in java.
-
Constructors can be overloaded in java.
-
The return type is same in method overriding.
-
None of the above
B
Correct answer
Explanation
We cannot override the static method in java because the derived class method hides the functionality of base class method and there is no runtime polymorphism.
-
We cannot create the objects of the abstract class.
-
Abstract class can have final methods.
-
A static method cannot be abstract.
-
Abstract class can have concrete methods.
-
None of the above
B
Correct answer
Explanation
This is a false statement as final methods cannot be overridden. So, the implementation of all the methods cannot be completed, and hence a abstract class cannot have final methods.
-
Their scope may be local.
-
Lifetime of a static variable is equal to the lifetime of the program.
-
They retain their value even during multiple calls to a function.
-
Static variables are stored in RAM.
-
The default value of static variables is zero.
E
Correct answer
Explanation
The default value of static variables is garbage.
-
Data abstraction
-
Data encapsulation
-
Inheritance
-
Polymorphism
-
Message passing
C
Correct answer
Explanation
Inheritance is the process of forming a new class from an existing class or base class.The base class is also known as parent class or super class, the new class that is formed is called derived class.Derived class is also known as a child class or sub class. Inheritance helps in reducing the overall code size of the program, which is an important concept in object-oriented programming.
-
Abstraction
-
Encapsulation
-
Multiple inheritance
-
Polymorphism
-
None of the above
C
Correct answer
Explanation
Multiple inheritance is not possible in java and interface is used instead of multiple inheritance in java.
-
Singleton design pattern is a creation design pattern in java.
-
There can be only one instance that can be created in a singleton design pattern in java.
-
We cannot make the subclass of the Singleton class.
-
All of the above
-
Only (1) and (2)
D
Correct answer
Explanation
Yes, all the above three statements determine the property of the Singleton design pattern in java.
-
It will give compile time error.
-
Code will compile.
-
The method in the first interface will be executed.
-
The method in the second interface will be executed.
-
None of the above
A
Correct answer
Explanation
Yes, the code will give compile time error as the compiler would not identify that which method to execute as they have conflicting return type.
-
The member of the class can be accessed inside the same package as well as in the subclass of the class in other package.
-
The member can be accessed only in the same package.
-
Members can be accessed inside the particular class only.
-
Members can be accessed everywhere outside the class as well as in the other packages too.
-
None of the above
A
Correct answer
Explanation
This is true about protected specifier in java.
-
It is used to hide the data from the outside view.
-
By using encapsulation we can use the properties of the base class in the subclass.
-
Encapsulation binds the data and code in a well defined interface.
-
All of the above
-
Both (1) and (3)
E
Correct answer
Explanation
Yes, (1) and (3) option determines the exact properties of the encapsulation in Object Oriented Programming.
-
A class can implement any number of the interfaces in java.
-
A class can extends more than one abstract class in java.
-
All the methods in an interface are abstract methods.
-
All of the above
-
Both (1) and (3)
E
Correct answer
Explanation
Yes, both of the alternatives are true,
-
Adapter
-
Singleton
-
Fecade
-
Observer
-
None of the above
B
Correct answer
Explanation
Yes, it is called the creational design pattern and is used to restrict a class to create more than one instances in java.
-
A constructor can not be inherited by the subclass.
-
A final method can not be override in the subclass.
-
A constructor can be declared final.
-
A final class can not be extended.
-
None of the above
C
Correct answer
Explanation
No, we can not declared a constructor as final because the final method can be inherited but can not be overridden and the constructor can not be inherited.
-
every class object definition must provide the required arguments
-
it is a compilation error
-
it is a runtime error
-
the compiler automatically inserts the default constructor
A
Correct answer
Explanation
The programmer has to follow the constructor signature.
-
member functions
-
member functions and friends of its class
-
member functions and derived class member functions
-
static functions
B
Correct answer
Explanation
Yes, it is correct for class access specifiers.
-
Derived Class
-
Base Class
-
Derived Class
Base Class
-
Base Class
Derived Class
D
Correct answer
Explanation
Base class constructor is called before derived class.