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. Cohesionn 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. None of these

  4. Cohesion is the OO principle most closely associated with making sure that a class is designed witha single well focussed principle

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

Cohesion is the OO principle that a class should have a single, well-focused purpose or responsibility. High cohesion means a class does one thing well. Hiding implementation details is encapsulation (information hiding), and knowing other classes only through APIs is also related to encapsulation and loose coupling, not cohesion.

Multiple choice technology programming languages
  1. Class D has low Cohesion

  2. Class B has weak encapsulation

  3. Class A has weak encapsulation

  4. Class B has strong encapsulation

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

If Class A methods use public methods in Class B, this indicates Class B has weak encapsulation because its internal methods are exposed and tightly coupled to other classes. Class A using variables in Class C violates encapsulation but the question asks what is 'most likely true', and Class B's weak encapsulation is directly stated. Class D has no relationship described, so its cohesion cannot be determined.

Multiple choice technology programming languages
  1. True

  2. False

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

The terminology is: the overridden method is in the PARENT class (the original version being replaced), and the overriding method is in the CHILD class (the new version). The statement reverses this correctly, so False is the right answer. You're overriding the parent's method from the child.

Multiple choice technology programming languages
  1. True

  2. False

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

You cannot reduce visibility when overriding - private is more restrictive than public. Java's overriding rules require the subclass method to have at least the same access level as the parent. Changing public void doIt() to private void doIt() violates this, so the code is illegal.

Multiple choice technology programming languages
  1. static because it has to be constant and cannot be changed.

  2. static because it has to be loaded by the JVM without instantiating it

  3. public because other classes may also call the main method of a class

  4. public because JVM has to have access to the main method in order to call it.

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

The main method must be static so the JVM can invoke it without creating an instance of the class (no object exists at program startup). It must be public so the JVM, which is external to your class, can access it. Static methods belong to the class itself, not instances, and public allows unrestricted access from outside.

Multiple choice technology platforms and products
  1. public is more restrictive than protected

  2. package (default access modifier) is more restrictive that private

  3. package is more restrictive that public

  4. package is more restrictive that protected

  5. protected is more restrictive that package

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

In Java, access modifiers restrict visibility in this order from most to least restrictive: private (only same class), package/default (same package), protected (same package + subclasses), public (everywhere). Since package-level access allows access only within the same package while protected additionally allows subclasses outside the package to access the member, package is indeed more restrictive than protected.

Multiple choice technology databases
  1. Mapper classes are Java classes that contain SQL Mapping Annotations that avoid the need for XML

  2. Mapper classes are Java classes that contain data Mapping Annotations that encourage the need for XML

  3. Mapper classes are Java classes that contain SQL that avoid the need for XML

  4. Mapper classes are O/R Mapping objects contain SQL Mapping objects that avoid the need for XML

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

Mapper classes in iBATIS are Java classes that use SQL Mapping Annotations to define database operations. This annotation-based approach can replace XML configuration, providing a more concise and type-safe way to map SQL statements to Java methods.

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.