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 databases
  1. a)Yes

  2. b)No

  3. c)

  4. d)

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

Yes, hiding private constructs in the package body is a key advantage of packages. This implements information hiding and encapsulation - the package specification exposes only what users need, while implementation details remain private and inaccessible. This prevents users from depending on or misusing internal implementation details, allowing the package developer to change the internal logic without affecting users.

Multiple choice technology programming languages
  1. a) Only local or packaged sub programs can be overloaded.

  2. b) Overloading allows different functions with the same name that differ only in their return types.

  3. c) Overloading allows different subprograms with the same number, type and order of the parameter.

  4. d) Overloading allows different subprograms with the same name and same number or type of the parameters.

  5. e) Overloading allows different subprograms with the same name but different in either number or type or order of parameter.

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

Package overloading in Oracle allows multiple subprograms with the same name if they differ in their parameter signatures. Only local or packaged subprograms can be overloaded (standalone subprograms cannot). The key rule is: same name but different in number, type, or order of parameters. Return types alone are insufficient for overloading - two subprograms differing only in return type would cause ambiguity.

Multiple choice technology programming languages
  1. a) Packages can be nested.

  2. b) You can pass parameters to packages.

  3. c) A package is loaded into memory each time it is invoked.

  4. d) The contents of packages can be shared by many applications.

  5. e) You can achieve information hiding by making package constructs private.

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

Oracle packages support information hiding through private constructs (package body vs specification) and enable code sharing across applications. Packages cannot be nested, you cannot pass parameters to packages themselves (only to their subprograms), and packages are loaded once per session then cached - not reloaded on each invocation. These design features make packages efficient and modular.

Multiple choice technology
  1. return super.hashCode();

  2. return name.hashCode() + age * 7;

  3. return name.hashCode() + comment.hashCode() / 2;

  4. return name.hashCode() + comment.hashCode() / 2 - age * 3;

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

The hashCode method must use the same fields as equals() to maintain the hashCode contract. The equals method compares age and name, so option B correctly uses only those fields. Options C and D incorrectly include 'comment' which is not part of equals comparison, violating the contract.

Multiple choice technology web technology
  1. True

  2. False

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

Abstract methods cannot be static because abstract methods are designed to be overridden in subclasses, while static methods belong to the class itself and are not inherited for overriding. Making a method both abstract and static would be a contradiction in terms.

Multiple choice technology web technology
  1. True

  2. False

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

Only objects of classes that implement the Cloneable interface can be cloned using the clone() method. Attempting to clone an object that does not implement this interface throws a CloneNotSupportedException.

Multiple choice technology testing
  1. Regular Expressions

  2. Parameterization

  3. Descriptive Programming

  4. All the Above

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

Descriptive Programming allows you to define objects dynamically in your code using property-value pairs, making it ideal for objects whose properties change at runtime. Regular Expressions have limited flexibility, while Parameterization is for test data, not object identification.

Multiple choice technology testing
  1. Object Spy

  2. Object Repository Manager

  3. Object Identification

  4. All the above

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

In UFT (Unified Functional Testing), Object Identification is the feature where you define and configure the mandatory and assistive properties that the tool uses to identify and recognize test objects during runtime. The Object Spy is used to view the properties and methods of an object at runtime, while Object Repository Manager is used to manage shared object repositories. Only Object Identification lets you configure how the tool identifies objects.

Multiple choice technology
  1. The equals method does NOT properly override the Object.equals method.

  2. Compilation fails because the private attribute p.name cannot be accessed in line 5.

  3. To work correctly with hash-based data structures, this class must also implement the hashCode method.

  4. When adding Person objects to a java.util.Set collection, the equals method in line 4 will prevent duplicates.

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

The equals method shown does NOT properly override Object.equals(Object obj) because it takes a Person parameter instead of Object. This violates the overriding contract - the signature must match. For proper overriding, the parameter should be Object with an instanceof check inside. This equals method will not be called polymorphically when a Person is compared to a non-Person Object.