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. Abstract class MyApplet extends java.applet.Applet {

  2. Public class MyApplet extends java.applet.Applet {

  3. Class MyApplet implements Applet {

  4. Public class MyApplet extends applet implements Runnable {

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

A valid applet declaration must be a public class that extends java.applet.Applet (or javax.swing.JApplet for Swing). Option B correctly declares 'Public class MyApplet extends java.applet.Applet' (assuming 'Public' is a typo for 'public'). Option A incorrectly uses 'abstract', option C incorrectly uses 'implements', and option D incorrectly combines 'extends applet' (should be 'extends java.applet.Applet') with 'implements Runnable'.

Multiple choice technology programming languages
  1. Can be overridden

  2. Cannot be overridden

  3. Can be inherited

  4. Cannot be inherited

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

A final method cannot be overridden in subclasses. This enforces that the implementation remains unchanged throughout the inheritance hierarchy. However, final methods can still be inherited and called by subclasses.

Multiple choice technology programming languages
  1. System

  2. User defined

  3. parametrized

  4. Hidden

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

In Caché ObjectScript, %classes refer to system classes - classes starting with % are provided by the system. User-defined classes don't use the % prefix. The claimed answer A (System) is correct.

Multiple choice technology programming languages
  1. Clientdatatype

  2. Abstract

  3. super

  4. classtype

  5. final

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

All five options are valid class keywords in Cache ObjectScript. Clientdatatype defines a custom data type class, Abstract prevents instantiation, super references the superclass, classtype defines the class category, and final prevents further inheritance or overriding. These keywords control class behavior and inheritance patterns.

Multiple choice technology programming languages
  1. Data type classes cannot be instantiated

  2. Data type classes can contain properties

  3. Data type classes automatically includes methods for validation and translation

  4. Data type classes cannot be inherited

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

Data type classes in Cache ObjectScript cannot be directly instantiated (they're abstract by nature) and automatically include methods for validation and translation when used. However, they CAN contain properties to define the data structure, and they CAN be inherited to create specialized data types. The claimed answer A and C are correct.

Multiple choice technology programming languages
  1. keywords are not inherted

  2. keywords from first superclass are inherited

  3. keywords from last superclass are inherited

  4. keywords from all superclasses are inherited

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

In Cache ObjectScript multiple inheritance, class keywords are inherited only from the first superclass in the inheritance list. Keywords from subsequent superclasses are not inherited. This prevents conflicts when multiple superclasses define conflicting keywords. The inheritance is determined by the order of superclasses in the class definition.

Multiple choice technology web technology
  1. BD

  2. DB

  3. BDC

  4. DBC

  5. Compilation fails

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

When a superclass lacks a no-argument constructor, subclasses must explicitly call a superclass constructor with matching arguments using super(...). Bottom2 fails to do this, causing compilation to fail because the implicit super() call cannot find a valid constructor in Top. The Top class only has Top(String s), so Bottom2's constructor must explicitly call super(s) or super(someString).

Multiple choice technology web technology
  1. Cohesion is the OO principle most closely associated with hiding implementation details

  2. Cohesion is the OO principle most closely associated with making sure that classes know about other classes only through their APIs

  3. Cohesion is the OO principle most closely associated with making sure that a class is designed with a single, well-focused purpose

  4. Cohesion is the OO principle most closely associated with allowing a single object to be seen as having many types

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

Cohesion measures how focused and single-purpose a class is. High cohesion means a class performs one logical task. Hiding implementation details is encapsulation, interface-only interaction is loose coupling, and treating objects as multiple types is polymorphism.

Multiple choice technology web technology
  1. furry bray

  2. stripes bray

  3. furry generic noise

  4. stripes generic noise

  5. Compilation fails

  6. An exception is thrown at runtime

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

Fields in Java are not polymorphic - they bind to the declared type (Mammal), so m.name returns 'furry '. Methods ARE polymorphic and use the actual object type (Zebra), so m.makeNoise() returns 'bray'. This is a key distinction between field access and method invocation in Java's inheritance model. Even though the object is a Zebra, field access is determined at compile time based on the reference type.

Multiple choice technology web technology
  1. ClassD has low cohesion

  2. ClassA has weak encapsulation

  3. ClassB has weak encapsulation

  4. ClassB has strong encapsulation

  5. ClassC is tightly coupled to ClassA

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

Direct access to another class's public variables violates encapsulation principles. ClassB should protect its data with private fields and provide access through getter/setter methods, making ClassB responsible for its own data management. When ClassA directly uses ClassB's public variables, ClassB has weak encapsulation because it exposes its internal implementation details.