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. No

  2. Yes

  3. Can be in special cases

  4. None

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

Static methods belong to the class rather than any specific object instance. Consequently, they do not have access to an instance context and cannot use the this keyword. Attempting to use this inside a static method results in a compile-time error, making 'No' the only correct option.

Multiple choice technology programming languages
  1. public

  2. synchronise

  3. private

  4. transient

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

Top-level classes (not nested inside another class) can only be marked 'public' or have default (package) access. Synchronized, private, and transient modifiers are not allowed at the top level - synchronized is used for methods, and private/transient are for class members. Options B, C, D are incorrect modifiers for top-level classes.

Multiple choice technology programming languages
  1. java.lang.object

  2. java.lang

  3. none

  4. java.lang.string

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

In Java, all classes implicitly extend from java.lang.Object, which is the root of the class hierarchy. The package name is java.lang, but the actual class name is Object (capitalized). Options B and D are incorrect - java.lang is a package, java.lang.String is a specific class. Option A has the class name capitalized correctly.

Multiple choice technology programming languages
  1. When a class is not to be instantiated,

  2. declare a method without providing the implementation

  3. cannot use a field declared abstract

  4. none

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

The abstract keyword in Java serves two main purposes: preventing class instantiation and declaring methods without implementation. Option A is correct because abstract classes cannot be instantiated directly - they must be extended by concrete subclasses. Option B is correct because abstract methods declare the method signature without providing a body, leaving the implementation to concrete subclasses. Options C and D are incorrect - abstract can be used with fields in certain contexts (though not abstract fields themselves), and abstract is a valid part of Java.

Multiple choice technology programming languages
  1. No

  2. Yes

  3. Will have to use an instance

  4. None

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

Private members of a superclass are NOT accessible in subclasses. This is a fundamental principle of encapsulation in Java - private access means class-level only. Even though subclasses inherit the parent, they cannot directly access private fields or methods. They must use public/protected getters or setters if available. Option A 'No' is correct.

Multiple choice technology testing
  1. Run-Time Object

  2. Test Object

  3. Smart Identification Object

  4. Assistive Object

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

The Object property in QTP provides access to the actual Run-Time Object's native methods and properties, bridging the test automation with the live application object. Test Objects are QTP's abstraction of application elements and don't expose the native runtime methods.

Multiple choice technology programming languages
  1. A B A

  2. A B A B

  3. B B

  4. A B

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

When creating B, constructors chain: prints 'A' then 'B'. During deserialization, constructors are NOT called for the serialized object itself, but the superclass no-arg constructor IS called for the non-serializable superclass A, printing 'A' again. Output: 'A B A'.

Multiple choice technology
  1. True

  2. False

  3. cant be said

  4. none of the above

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

Method overloading (defining multiple methods with the same name but different parameters) does not block inheritance. A subclass can overload methods while still inheriting all other methods from its superclass. Overloading and inheritance are independent concepts - a class can both inherit from a superclass and overload its own methods.

Multiple choice technology
  1. native

  2. synchronize

  3. protected or private.

  4. All of the above

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

Interface declarations in Java can only be public or package-private (default access). They cannot be declared with modifiers like native, synchronized, protected, or private. These keywords apply to specific methods or class features, not to interface declarations themselves.

Multiple choice technology testing
  1. By class and properties

  2. By class and methods

  3. By methods and properties

  4. By class only

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

QTP identifies objects by their class (type) and a set of properties that uniquely distinguish them from other objects. Methods define what actions can be performed on the object but are not used for identification during recording.

Multiple choice technology programming languages
  1. True

  2. False

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

Parent's 'set' field is public, so Child can access it. The package syntax is valid. Java's Set accepts String values, so set.add("Hello") compiles. There are no compilation errors, so the answer True is correct.

Multiple choice technology programming languages
  1. public, abstract

  2. abstract, final

  3. final

  4. public

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

Methods in an interface are implicitly public and abstract. The 'public' modifier ensures they can be accessed from anywhere, and 'abstract' indicates they must be implemented by the implementing class. Methods cannot be 'final' in an interface because that would prevent implementation, which defeats the purpose of an interface.

Multiple choice technology programming languages
  1. string

  2. class

  3. delegate

  4. struct

  5. interface

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

In C#, value types are stored directly on the stack and contain their actual data. Structs are value types, while classes, delegates, interfaces, and strings are reference types that store references to heap-allocated objects.