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
-
prints m1 method in C1 class
-
prints m1 method in anonumous class
-
compile time error
-
Runtime error
-
none of the above
B
Correct answer
Explanation
The m1() method in c2 returns an anonymous subclass of c1 that overrides the m1() method. When ob1.m1() is called on this returned object, Java's dynamic dispatch invokes the overridden version in the anonymous class, printing 'm1 mehod in anonymous class' (note the typo 'mehod').
A
Correct answer
Explanation
When instantiating B, constructors of A then B run, printing 'A' and 'B'. During deserialization, because superclass A is not serializable, its no-arg constructor is invoked, printing 'A' again, while serializable B's constructor is bypassed. This results in the sequence 'A B A'.
-
Classes that end in “-” must be abstract by convention
-
Abstract classes can not have instances
-
Concrete classes must belong to a class group
-
A class group must always have at least one key
-
"$baseclass"
-
"@baseclass"
-
pegabaseclass
-
pzBaseClass
B
Correct answer
Explanation
In PegaRULES Process Commander (PRPC), @baseclass is the ultimate base class from which all other classes inherit. It contains standard properties, activities, and rules available to all applications. Other choices like $baseclass or pzBaseClass are syntactically or contextually incorrect.
-
Inherits from @baseclass
-
Inherits from Work-
-
Contains most of your business logic
-
Is usually the same as a “bottom level” class
A
Correct answer
Explanation
A Top-level Class in Pega PRPC inherits from @baseclass, which is the ultimate parent class in the Pega class hierarchy. Work- is for work objects (cases), not top-level classes. While top-level classes contain business logic, that's not what defines them as top-level. They are not the same as bottom-level classes, which are leaf nodes in the hierarchy.
A
Correct answer
Explanation
The String class in Java is declared final, meaning it cannot be extended or subclassed. This design choice ensures that String's immutability guarantees and thread-safety properties cannot be compromised through inheritance.
-
transient
-
synchronized
-
volatile
-
abstract
B,D
Correct answer
Explanation
The 'synchronized' keyword cannot be used with instance variables - it is used only with methods, blocks, or static methods to control thread access. The 'abstract' keyword is used for classes and methods, not instance variables. 'transient' and 'volatile' are valid modifiers for instance variables - transient prevents serialization, while volatile ensures visibility across threads.
-
class someclass extends mainclass
-
protected class someclass extends mainclass
-
public class someclass extends mainclass
-
private class someclass extends mainclass
C
Correct answer
Explanation
When writing a utility class that extends another class and will be used by multiple classes in different packages, it must be declared 'public' to be accessible outside its own package. 'protected' would only allow subclass access, 'private' would prevent any external access, and the default (package-private) wouldn't allow cross-package use.
-
class someclass extends mainclass
-
protected class someclass extends mainclass
-
public class someclass extends mainclass
-
private class someclass extends mainclass
C
Correct answer
Explanation
To make a Java class accessible to classes in different packages, the class must be declared as public. Default (package-private), protected, or private access modifiers would restrict visibility, preventing external packages from using it.
-
transient
-
synchronized
-
volatile
-
abstract
B,D
Correct answer
Explanation
Instance variables cannot use modifiers that apply to methods or classes. 'synchronized' is a method-level keyword for thread safety and 'abstract' applies to classes and methods. 'transient' and 'volatile' are valid instance variable modifiers for serialization and thread visibility respectively.
B
Correct answer
Explanation
In object-oriented systems like Documentum, an object is a single instance of an object type or class, not a 'multiple instance.' Object types define the structure, and multiple objects can be created from that type, but each individual object represents one instance of that type.
-
Persistent
-
Non Persistent
-
No objects are created
-
type of object is not predictable
B
Correct answer
Explanation
Non-persistent (transient) objects exist only during a session and are destroyed when the session terminates. These objects are created at runtime for temporary operations and are not stored in the database, making them ideal for short-lived processing needs.
B
Correct answer
Explanation
Object Identification in QTP/UFT is used to define and configure the properties used to uniquely identify objects during test execution. It does not retrieve runtime values - for that, you would use methods like GetROProperty to retrieve runtime object properties.
-
Ref
-
Obj
-
Set
-
None of the above
C
Correct answer
Explanation
In VBScript, the Set keyword is mandatory when assigning object references to variables. This distinguishes object assignment from regular value assignment. Using Ref or Obj are not valid VBScript keywords for this purpose.
-
Polymorphism
-
Inheritance
-
Name Mangling
-
Function Signature
C
Correct answer
Explanation
While function signatures define the overload, the compiler uses Name Mangling to generate unique names for functions with identical names but different signatures, allowing the linker to distinguish and resolve the calls correctly at runtime.