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 technology programming languages
  1. Since enums are comparable to traditional classes, they may not be arguments in switch statements.

  2. Enums may not extend another class/ enum.

  3. Enums inherit the java.lang.Object class.

  4. Enums may be extended by another Enum.

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

In Java, enums can be used in switch statements, making the first option incorrect. Java enums also implicitly extend java.lang.Enum (not java.lang.Object directly, though Enum inherits Object) and cannot be extended or extend other classes. Thus, options 1 and 4 are incorrect and correctly marked.

Multiple choice technology programming languages
  1. yes

  2. No

  3. sometimes only

  4. none of these

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

Abstract classes cannot be instantiated directly because they are designed to be incomplete. You must create a concrete subclass that implements all abstract methods before you can create objects. Only concrete subclasses can be instantiated using the new keyword.

Multiple choice technology programming languages
  1. Using interface

  2. Class should be declared as private

  3. yes

  4. A class does not inherit constructors from any of its superclasses.

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

Constructors are not inherited in Java - each class must define its own constructors. A subclass can call a superclass constructor using super(), but this is explicit invocation, not inheritance. If you don't write any constructor, Java provides a default no-arg constructor that calls super().

Multiple choice technology web technology
  1. True

  2. False

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

The Struts Action class uses the Adapter pattern by providing a common interface (execute() method) that adapts application-specific logic to the framework's expected contract. Different Action implementations 'adapt' their specific processing to the standard Action interface.

Multiple choice technology packaged enterprise solutions
  1. Types Tab

  2. Detail Tab

  3. Flat Tab

  4. All of Above

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

In Siebel Tools, the Types tab in the Object Explorer displays the hierarchical parent-child relationships among all object definitions, allowing developers to see how objects are structured relative to one another. The Detail and Flat tabs display object instances or a flat list rather than schema hierarchies.

Multiple choice technology programming languages
  1. public void class

  2. object class

  3. inner class

  4. outer class

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

In Java, java.lang.Object is the root of the class hierarchy. Every Java class implicitly or explicitly extends Object, making it the ultimate superclass. 'public void class' is invalid syntax, and inner/outer classes are nesting patterns.

Multiple choice technology programming languages
  1. True

  2. False

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

The main() method must be declared static so the JVM can call it without instantiating the class. This is a fundamental Java requirement - the JVM needs an entry point it can invoke using the class name directly, without needing to create an object first.

Multiple choice technology programming languages
  1. A class can extend multiple classes

  2. An interface can extend multiple classes

  3. An interface can implement multiple interfaces

  4. A class can extend multiple interfaces

  5. A class can implement multiple interfaces

  6. An interface can extend multiple interfaces

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

In Java, multiple inheritance of implementation is not supported for classes, so a class can only extend one class, but it can implement multiple interfaces. Additionally, an interface can extend multiple other interfaces to combine behaviors.

Multiple choice technology programming languages
  1. To avoid having to declare variables.

  2. To refer to a class without using prefixes.

  3. To avoid calling methods.

  4. To import the images you want to use.

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

Java import statements allow you to reference classes by their simple names instead of fully-qualified names. They don't affect variable declaration (A), method calling (C), or handle images (D). Imports are purely a compile-time naming convenience.

Multiple choice technology programming languages
  1. Two methods defined in that interface.

  2. All methods defined in that interface.

  3. Only certain methods in an interface.

  4. Any methods in a class.

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

Implementing an interface establishes a contract requiring the implementing class to provide concrete behavior for all methods defined within that interface. Providing behavior for only a subset of methods or arbitrary class methods violates this contract and prevents compilation unless the implementing class is abstract.

Multiple choice technology programming languages
  1. Two methods defined in that interface.

  2. Only certain methods in an interface.

  3. All methods defined in that interface.

  4. Any methods in a class.

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

When a Java class implements an interface, it enters a contract to provide concrete implementations for ALL methods declared in that interface. This is a fundamental rule of Java interfaces - you cannot pick and choose which methods to implement. Option A incorrectly limits it to only two methods, while option B is also incorrect because the implementation must be complete, not selective.

Multiple choice technology programming languages
  1. To avoid having to declare variables.

  2. To refer to a class without using prefixes.

  3. To avoid calling methods.

  4. To import the images you want to use.

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

To answer this question, the user needs to understand the purpose of import statements in programming.

Option A: This option is incorrect. Import statements have nothing to do with declaring variables. Import statements are used to access classes, functions, and other resources from external modules.

Option B: This option is correct. One of the main advantages of using import statements is that they allow you to refer to a class without having to use a prefix. For example, if you import the "math" module in Python, you can use the "sqrt" function without having to write "math.sqrt" every time.

Option C: This option is incorrect. Import statements are not used to avoid calling methods. In fact, import statements are often used to make it easier to call methods from external modules.

Option D: This option is incorrect. Import statements are not used to import images. They are used to import code from external modules.

Therefore, the correct answer is:

The Answer is: B. To refer to a class without using prefixes.

Multiple choice technology programming languages
  1. Two methods defined in that interface.

  2. All methods defined in that interface.

  3. Only certain methods in an interface.

  4. Any methods in a class.

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

When a class implements an interface, it enters a contract to provide concrete implementations for ALL methods declared in that interface. This ensures that any object of the class can be used polymorphically wherever the interface type is expected. Partial implementation is not allowed for non-abstract classes.

Multiple choice technology programming languages
  1. Two methods defined in that interface.

  2. Only certain methods in an interface.

  3. All methods defined in that interface.

  4. Any methods in a class.

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

When a class implements an interface in Java, it must provide concrete implementations for ALL methods declared in that interface (unless the class is declared abstract). This is a contract - the interface promises certain behaviors, and the implementing class must deliver them. Option A is incorrect because it's not limited to just two methods - it's all methods.