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. i. and iv. both are true

  2. i. and iii. both are true

  3. ii. and iv. both are true

  4. ii. and iii. both are true

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

This answer is correct. Both the options are correct. Final methods cannot be overridden. Similarly, variables declared as final cannot be changed and are always constants.

Multiple choice
  1. Only i.is true

  2. Only ii. is true

  3. Only iii.is true

  4. Only iv. is true

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

This answer is correct. A local inner class may only be final or abstract and cannot be static or any other modifier.

Multiple choice
  1. i. and iii both are correct

  2. i. and iv. both are correct

  3. ii. and iii. both are correct

  4. ii. and iv. both are correct

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

This answer is correct. A nested class will have access to the members in the outer class including its private members. Also an inner class is always a non-static class and it has access to all the other non-static members of the outer class.

Multiple choice
  1. i. is true

  2. ii. is true

  3. iii. is true

  4. iv. is true

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

This answer is correct. if the value of the object is not changed, then the object is called an immutable object else it is called a mutable object.

Multiple choice
  1. i

  2. ii

  3. iii

  4. iv

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

This answer is correct. Float and Double classes has a static method is Nan() method taking  float value if it is called from Float class and takes double value if it is called from Double class. Also, Float and Double classes has a non-static method is Nan() which will return true if the invoking object contains a value that is not a number. Else it returns false.

Multiple choice
  1. ii. and iii. are true

  2. ii. and iv. are true

  3. i. and iii. are true

  4. i. and iv. are true

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

This answer is correct. Constructors never have return type whereas other methods may or may not have return types. Also, Constructors must have the same name as that of the class name and the other method names may or may not have the same name as that of the class name.

Multiple choice
  1. i

  2. ii

  3. iii

  4. iv

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

This answer is correct. Float and Double classes has one static isInfinite() method and a non-static method is Infinite() method.The non-static method takes float number when invoked from Float class and will return true if the invoking object contains an infinite value.The non-static method takes double number when invoked from Double class and will return true if the invoking object contains an infinite value whereas static method will return true if the number specified is an infinte value in both the classes else return false.

Multiple choice
  1. Default members can be accessed only by classes in the same package.

  2. Protected members can be accessed by other classes in the same package only.

  3. A protected member inherited by a subclass from another package is not accessible to any other class in the subclass package, except for the subclasses of the subclass.

  4. Public members cannot be accessed in other packages.

  5. Both (2) and (4)

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

.