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. Its non-static members

  2. Static members of the enclosing class

  3. Its Static members

  4. Non-Static members of the enclosing class

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

Static nested classes cannot access instance (non-static) members of the enclosing class because they are not associated with any instance of the enclosing class. They can only access static members of the enclosing class and their own members (both static and non-static).

Multiple choice technology programming languages
  1. They can be applied to both data & methods

  2. They must precede a class's data variables or methods

  3. They can follow a class's data variables or methods

  4. They can appear in any order

  5. They must be applied to data variables first and then to methods

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

Access modifiers may be applied to both data members and methods, must precede the member they modify, and can appear in any order relative to other modifiers. They cannot follow a member declaration, and there is no requirement to place them on data before methods, so those statements are false.

Multiple choice technology programming languages
  1. Public

  2. Private

  3. Abstract

  4. Final

  5. Protected

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

Top-level classes (not inner classes) can only have public or package-private (no modifier) access. They can additionally be abstract or final. Private and protected are NOT allowed for top-level classes - these modifiers only apply to class members (fields, methods, inner classes).

Multiple choice technology programming languages
  1. Prints true,false

  2. Print false,true

  3. Prints true,true

  4. compile time error

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

ob2 references the same object as ob1, which is an instance of c1. Therefore ob2 instanceof Object is true and ob2 instanceof c1 is also true, giving the output true true. The stored answer matches this result.

Multiple choice technology programming languages
  1. Casting/Uncasting

  2. Boxing/Unboxing

  3. Packing/Unpacking

  4. Stack & Heap Conversion

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

Boxing converts a value type to a reference type by storing it on the heap and creating a reference to it. Unboxing reverses this by extracting the value type from the reference. The other terms like packing/uncasting are not standard terminology in .NET or Java.

Multiple choice technology programming languages
  1. are public

  2. are serializable

  3. are immutatable

  4. extend java.lang.Number

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

All wrapper classes in Java are immutable, meaning their values cannot be changed after creation. While all are public and serializable, and most extend Number, the statement about immutability is the correct answer to what IS true (despite the question asking what 'aren't' true).

Multiple choice technology packaged enterprise solutions
  1. SessionContext

  2. ApplicationContext

  3. FormContext

  4. None of the above

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

In ClarifyCRM's object model, BOContext (Business Object Context) inherits from FormContext, which provides the base functionality for managing form-level data and operations within the application framework. Options A and B are incorrect context types.

Multiple choice technology programming languages
  1. the new method should return int

  2. the new method can return any type of values

  3. the argument list of new method should exactly match that of overriden method

  4. the return type of new method should nottch that of overriden method

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

When overriding a method in Java, the argument list (method signature) must exactly match the original method. The return type can be the same or a covariant type (subtype), but the parameter types, order, and number must remain identical for proper override behavior.

Multiple choice technology programming languages
  1. I am in Static. I am in Static1. Before calling. I am in Init. Constructor. I am in Init. Constructor.

  2. Before calling. I am in Static. I am in Static1. I am in Init. Constructor. I am in Init.Constructor.

  3. Before calling. I am in Static. I am in Static1. Constructor. I am in Init. Constructor. I am in Init.

  4. Before calling. Constructor. I am in Static. I am in Static1. I am in Init. Constructor. I am in Init.

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

Static initialization blocks execute first when the class loads, in the order they appear. Then the main method executes. When objects are created with 'new', instance initialization blocks execute before the constructor. Static blocks run only once per class load, not per object creation.

Multiple choice technology programming languages
  1. True

  2. False

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

Methods in a class can share the same name through method overloading, as long as they have different parameter lists (signatures). The compiler distinguishes them by the number, types, and order of parameters. The statement is false because method overloading is a fundamental feature of object-oriented programming.

Multiple choice technology programming languages
  1. True

  2. False

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

Constructors are special methods that initialize objects and never have a return type, not even void. They must have the same name as their class and are automatically called when an object is created using the new keyword. The presence of any return type (including void) would make it a regular method, not a constructor.

Multiple choice technology programming languages
  1. public Thread(Object obj)

  2. public Thread(String name)

  3. public Thread(Runnable trgt)

  4. public Thread(ThreadGroup grp, Runnable trgt, String name)

  5. public Thread(ThreadGroup grp, Object ob)

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

Thread constructors accept either a Runnable object (for the task to execute), a ThreadGroup, a name string, or combinations thereof. Option A is invalid because Thread doesn't accept a plain Object parameter. Option E is invalid because Object doesn't implement Runnable. Options B (String name), C (Runnable target), and D (ThreadGroup + Runnable + name) match valid Thread constructor signatures in Java.

Multiple choice technology programming languages
  1. A

  2. B

  3. C

  4. D

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

Point is a static nested class inside Line. To call getPoint() (an instance method), you need a Line instance: (new Line()).getPoint(). Since Point is defined inside Line, the full type is Line.Point. Option D correctly combines both: Line.Point p = (new Line()).getPoint(). Options A and C miss the Line. prefix for the nested class type. Option B is missing the Line instance.

Multiple choice technology programming languages
  1. A

  2. B

  3. C

  4. D

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

Calling s.defaultWriteObject() is the standard Java serialization approach to write the default serializable fields of the class to the stream, maintaining serialization compatibility.