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. CLR (Common Language Runtime) compiles the source code into intermediate language.

  2. CLR provides type safety to the code.

  3. CLR provides language independence in .Net framework.

  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 three statements are true.

Multiple choice
  1. It provides data encapsulation.

  2. It resolves the multiple inheritance problem in java.

  3. It provides the behaviour of the application.

  4. All of the above

  5. Only (1) and (2)

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

Yes, all of the above statements are true.

Multiple choice
  1. All the statements are true.

  2. Only R, S are true.

  3. Only Q, R, S are true.

  4. Only Q is true.

  5. Only P, R, S are true.

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

P) Abstract class cant be instantiated , rather we instantiate sub classes which extends abstract classes. Q) Yes, abstract should contain atleast one abstract method. If there is no abstract method, then it doesnt have any difference with general class. R) Yes , all variables declared in interface are implicitly static , public ,final & public. S) Yes, all the mehods in interface all implicitly abstract in nature which makes interface as pure abstract class. Hence Q,R and S are true.

Multiple choice
  1. All the statements P, Q, R and S are true.

  2. Only P, Q and R are true.

  3. Only S is true.

  4. Only R and S are true.

  5. None of the above

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

 P) Private access modifier restricts the access of the member to the outside classes. Q) Public members can be accessed by any class. R) Static indicates that JVM creates objects to static items without any instance, hence object creation is not necessary for static items. S) Protected members of a class can be accessed only its child classes and cannot be accessed by other classes. P,Q,R and S are true.

Multiple choice
  1. Constructor A Constructor B Member function B

  2. Constructor B Constructor A Member function B

  3. Constructor A Constructor B Member function A

  4. Constructor B Constructor A Member function A

  5. None of the above

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

Whenever we create object for child class, the constructor of parent class is invoked first. Then the child class constructors are invovled. This is because some of the fields in child class derived from parent class remain unintialized, when we invoke directly the constructor of child class. Hence parent class constructor is invoked first rather and constructor of child class is invoked later. b.func(); imvokes child class func() because of method overriding. Hence only child class func() method is invoked but not the func() method in parent class. Hence the ouput will be: Constructor A Constructor B Member function B

 

Multiple choice
  1. with argument in class A without argument in class B

  2. without argument in class A without argument in class B with argument in class B

  3. without argument in class A with argument in class B

  4. without argument in class A without argument in class B with argument in class B with argument in class B

  5. None of the above

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

  B a=new B(1); // object is created for child class B which has parameter, hence it calls constructor of class B with single argument but not default constructor of B. Every constructor in child class implicitly calls default constructor of base class i.e A. Hence "without argument in class A" is printed first. Now the control is returned back to constructor of child class with one arument i.e B(int a) Now the remaining part is executed which prints "with argument in class B" is printed next. The implicit representation of B(int a) is given as  B()    {        super();    //which calls default constructor of base class        System.out.println("without argument in class B");    }

The output will be: without argument in class A with argument in class B

Multiple choice
  1. Implementation of an abstract data type is hidden.

  2. Most OOP languages provide the feature of user-defined abstract data types.

  3. ADTs are a mathematical specification of a set of data.

  4. The ADT is represented by an interface.

  5. An abstract data type and data structure used in its implementation are the same.

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

There is a distinction, although sometimes subtle, between the abstract data type and the data structure used in its implementation. For example, a List ADT can be represented using an array-based implementation or a linked-list implementation. A List is an abstract data type with well-defined operations (add element, remove element, etc.) while a linked-list is a pointer-based data structure that can be used to create a representation of a List. The linked-list implementation is so commonly used to represent a List ADT that the terms are interchanged and understood in common use.

Multiple choice
  1. An interface can not have static method in java.

  2. We can declare abstract class without any abstract method in java.

  3. If we declare main method as private in java then the program will compile.

  4. All of the above.

  5. Only (1) and (3) are true.

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

Yes, all of the above are the true statements in java.

Multiple choice
  1. A constructor has the same name as a class name.

  2. Destructors are used to release the resources.

  3. A constructor can be private in C++.

  4. All of the above.

  5. None of the above

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

This is the correct choice.

Multiple choice
  1. Java supports structures or unions.

  2. Java allows the use of default arguments.

  3. Java includes preprocessor and support the preprocessor directives.

  4. Java supports typedef.

  5. Java supports use of applets.

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

This is the correct option as java supports the concept of applets.