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

Multiple choice
  1. We can overload the main method in java.

  2. We can override the static method in java.

  3. Constructors can be overloaded in java.

  4. The return type is same in method overriding.

  5. None of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. We cannot create the objects of the abstract class.

  2. Abstract class can have final methods.

  3. A static method cannot be abstract.

  4. Abstract class can have concrete methods.

  5. None of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. Their scope may be local.

  2. Lifetime of a static variable is equal to the lifetime of the program.

  3. They retain their value even during multiple calls to a function.

  4. Static variables are stored in RAM.

  5. The default value of static variables is zero.

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

The default value of static variables is garbage.

Multiple choice
  1. Data abstraction

  2. Data encapsulation

  3. Inheritance

  4. Polymorphism

  5. Message passing

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. Singleton design pattern is a creation design pattern in java.

  2. There can be only one instance that can be created in a singleton design pattern in java.

  3. We cannot make the subclass of the Singleton class.

  4. All of the above

  5. Only (1) and (2)

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Yes, all the above three statements determine the property of the Singleton design pattern in java.

Multiple choice
  1. It will give compile time error.

  2. Code will compile.

  3. The method in the first interface will be executed.

  4. The method in the second interface will be executed.

  5. None of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. The member of the class can be accessed inside the same package as well as in the subclass of the class in other package.

  2. The member can be accessed only in the same package.

  3. Members can be accessed inside the particular class only.

  4. Members can be accessed everywhere outside the class as well as in the other packages too.

  5. None of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

This is true about protected specifier in java.

Multiple choice
  1. It is used to hide the data from the outside view.

  2. By using encapsulation we can use the properties of the base class in the subclass.

  3. Encapsulation binds the data and code in a well defined interface.

  4. All of the above

  5. Both (1) and (3)

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

Yes, (1) and (3) option determines the exact properties of the encapsulation in Object Oriented Programming.

Multiple choice
  1. A class can implement any number of the interfaces in java.

  2. A class can extends more than one abstract class in java.

  3. All the methods in an interface are abstract methods.

  4. All of the above

  5. Both (1) and (3)

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

Yes,  both of the alternatives are true,

Multiple choice
  1. A constructor can not be inherited by the subclass.

  2. A final method can not be override in the subclass.

  3. A constructor can be declared final.

  4. A final class can not be extended.

  5. None of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. member functions

  2. member functions and friends of its class

  3. member functions and derived class member functions

  4. static functions

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Yes, it is correct for class access specifiers.