Computer Knowledge

Object-Oriented Programming

2,239 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 technology programming languages
  1. a class implements one or more interfaces

  2. a class extends one or more interfaces

  3. an interface extends one of more interfaces

  4. Serializable is a marker Interface

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

Classes IMPLEMENT interfaces, not extend them. Option B claims classes extend interfaces, which is false - you use 'implements' keyword for interfaces. Classes extend other classes, and interfaces extend other interfaces.

Multiple choice technology web technology
  1. By reference

  2. By object copy

  3. By producing a serialized copy

  4. None

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

When passing objects to remote methods in Java RMI, objects are passed by serialized copy (deep copy). This serialization process creates an object copy on the receiving side. By reference is not possible across JVM boundaries.

Multiple choice technology programming languages
  1. Abstract Class

  2. Interface

  3. Final Method

  4. none of the above

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

Java doesn't support multiple inheritance of classes to avoid the diamond problem and complexity. However, a class can implement multiple interfaces, which is the only way to achieve multiple inheritance in Java. Abstract classes follow single inheritance rules, and final methods prevent overriding entirely.

Multiple choice technology programming languages
  1. True

  2. False

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

Final methods in Java cannot be overridden. The final keyword specifically prevents a method from being modified or redefined by subclasses. This is used when you want to ensure a method's implementation remains consistent and unchanged throughout the inheritance hierarchy for security or design reasons.

Multiple choice technology programming languages
  1. class A,class B extends A,class C extends B

  2. class A implements B,implements C

  3. class A extends B,extends C

  4. none of the above

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

Multilevel inheritance occurs when a class is derived from another derived class. 'Class B extends A' and 'Class C extends B' forms a chain (A -> B -> C), which is the definition of multilevel inheritance.

Multiple choice technology programming languages
  1. one per method

  2. one per object

  3. one per class

  4. one per package

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

In Java, the 'static' keyword indicates that a member (field or method) belongs to the class itself rather than to individual instances (objects) of the class. There is only one copy of a static member shared by all instances.

Multiple choice technology programming languages
  1. Autounboxing

  2. Autoboxing

  3. polymorphism

  4. encapsulation

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

Autoboxing is Java's automatic conversion from primitive types (int, double, boolean) to their corresponding wrapper class objects (Integer, Double, Boolean). The reverse conversion (wrapper to primitive) is called unboxing. Polymorphism and encapsulation are unrelated OOP concepts.

Multiple choice technology programming languages
  1. A,C,B

  2. C,B,A

  3. A,B,C

  4. none of the above

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

In Java inheritance, when a subclass object is instantiated, the constructors are called in order from the top of the hierarchy down. Thus, the constructor for A (superclass) runs first, then B, then C (subclass).

Multiple choice technology programming languages
  1. String

  2. Integer

  3. Boolean

  4. Character

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

Wrapper classes in Java wrap primitive types (like Integer for int, Boolean for boolean, Character for char) to allow primitives to be used in contexts requiring objects. String, however, is not a wrapper class - it's an immutable class that represents a sequence of characters, not a wrapper for a primitive type. Option A is correct.

Multiple choice technology programming languages
  1. import java.awt.*;package Mypackage;class Myclass {}

  2. package MyPackage;import java.awt.*;class MyClass{}

  3. /This is a comment */package MyPackage;import java.awt.;class MyClass{}

  4. class Myclass {};import java.awt.*;package Mypackage;

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

Java requires package declaration (if present) to come before import statements. Comments can appear before the package. Option A has the wrong order, D has package after class, while B and C follow the correct structure.

Multiple choice technology programming languages
  1. Only 2

  2. Both 1 and 3

  3. 4

  4. Both 2 and 4

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

System.Collections.ArrayList is non-generic and CAN store multiple data types (statement 2 is true, so 1 is false). System.Collections.Generic.List is generic and enforces a single type (statement 4 is true, so 3 is false). The question asks which statements are FALSE - statements 1 and 3 are both false.