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. public class MinMax<?> {

  2. public class MinMax<? extends Number> {

  3. public class MinMax<N extends Object> {

  4. public class MinMax<N extends Number> {

  5. public class MinMax<? extends Object> {

  6. public class MinMax<N extends Integer> {

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

The type parameter N must extend Number to have the doubleValue() method. Option D (N extends Number) is correct. Option F (N extends Integer) also works since Integer extends Number and has doubleValue(). Options with ? are invalid because ? is a wildcard, not a type parameter name.

Multiple choice technology programming languages
  1. Starting of Main block Static block In the Main block Display block

  2. Static block Display block Starting of Main block In the Main block Display block

  3. Error: Non static method cannot accessed from static context

  4. Starting of Main block In the Main block Display block

Reveal answer Fill a bubble to check yourself
B Correct answer
Multiple choice technology programming languages
  1. The type List is assignable to List<A>.

  2. The type List<Object> is assignable to List<?>.

  3. The type List<D> is assignable to List<? extends B>.

  4. The type List<? extends A> is assignable to List<A>.

  5. The type List<Object> is assignable to any List reference.

  6. The type List<? extends B> is assignable to List<? extends A>.

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

In Java generics, wildcard types are used for covariance. List is assignable to List&gt;, List is assignable to List extends B&gt; because D extends B, and List extends B&gt; is assignable to List extends A&gt; because B extends A.

Multiple choice technology programming languages
  1. Error: Super(java.lang.String) in Super cannot be applied to ()

  2. First Second

  3. Second First

  4. Runtime Exception

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

The program compiles successfully because the superclass constructor Super(String s) is explicitly called. During execution, sub.name is "Second" and sup.name is "First", printing "Second First".

Multiple choice technology programming languages
  1. public void foo() { }

  2. public int foo() { return 3; }

  3. public Two foo() { return this; }

  4. public One foo() { return this; }

  5. public Object foo() { return this; }

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

When overriding a method, you can keep the same return type (One) or use a covariant return type (a subclass of One). Two is a subclass of One, so option C is valid covariant return. Option D keeps the original return type One. Options A and B change return type to void/int which aren't covariant with One. Option E returns Object which is a superclass, not allowed.

Multiple choice technology programming languages
  1. Color skyColor = BLUE;

  2. Color treeColor = Color.GREEN;

  3. Color purple = new Color( 0xff00ff);

  4. if( RED.getRGB() < BLUE.getRGB() ) {}

  5. Color purple = Color.BLUE + Color.RED;

  6. if( Color.RED.ordinal() < Color.BLUE.ordinal() ) {}

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

In enum code within the class, enum constants must be qualified with the enum name. Option B correctly references Color.GREEN. Option F uses Color.RED.ordinal() and Color.BLUE.ordinal() which are valid enum methods. Option A fails because BLUE isn't qualified. Option C tries to instantiate an enum with new which is illegal. Option D has the same qualification issue. Option E attempts to add enum values which isn't defined.

Multiple choice technology databases
  1. Single Project

  2. Multiple project

  3. Multiple projects of same type

  4. None of the above

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

A VOB (Versioned Object Base) can contain and support multiple projects simultaneously. This allows different projects to share common versioned elements while maintaining their own development streams. Option A is too restrictive, and option C unnecessarily limits projects to the same type.

Multiple choice technology programming languages
  1. CCmdTarget

  2. CObject

  3. CDocument

  4. CView

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

In MFC's class hierarchy, CObject is the ultimate root base class from which all other MFC classes derive. It provides core functionality like serialization, RTTI, and diagnostic support. CCmdTarget, CDocument, and CView all inherit from CObject either directly or indirectly.

Multiple choice technology web technology
  1. Implements java.io.Serializable

  2. Override equals() method

  3. Override hashCode() method

  4. Both a, b and c

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

Hibernate component classes must implement java.io.Serializable to support caching and detach operations. They should override equals() and hashCode() to work correctly in collections and as map keys. All three requirements ensure proper behavior in Hibernate's persistence framework.

Multiple choice technology web technology
  1. Transient, persistent, destroyed

  2. Transient, stored, detached

  3. Transient, persistent, detached

  4. open, close, detached

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

Hibernate persistent objects have three states: transient (new objects not associated with a session), persistent (associated with a session and managed), and detached (previously persistent but session closed). The 'destroyed' option is incorrect as it's not a Hibernate state.

Multiple choice technology programming languages
  1. CWnd

  2. CFrameWnd

  3. CObject

  4. CWinThread

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

In MFC hierarchy, CWinApp derives from CWinThread. CWinThread handles message loops and thread management. CObject is the ultimate base, CFrameWnd derives from CWnd, and CWinApp/CWinThread are parallel branches from CObject.

Multiple choice technology platforms and products
  1. A public class which contains a main method with proper signature (Arguments, return types etc).

  2. We can run any classes

  3. Only those classes which have public no argument constructors.

  4. None of these

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

In Eclipse Package Explorer, you can directly run any class that has a properly defined main method. The main method must be public, static, void, and accept a String array as its parameter. Simply having a public class or constructor is not sufficient for direct execution.

Multiple choice technology programming languages
  1. public static int main(char args[])

  2. public static void main(String args[])

  3. public static void MAIN(String args[])

  4. public static void main(String args)

  5. public static void main(char args[])

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

The Java runtime looks for a method with the exact signature public static void main(String[] args) to start program execution. The array notation can be written as String[] args or String args[], both are equivalent. The method must be public, static, return void, and accept a String array as its parameter.