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
-
0 bytes
-
1 bit
-
same as sizeof(int)
-
1 byte
D
Correct answer
Explanation
In C++, an empty class has a size of 1 byte to ensure that different instances of the class have distinct memory addresses, which is necessary for pointer arithmetic and identity comparisons.
D
Correct answer
Explanation
In C++ class declarations, you cannot initialize static, const, or extern variables directly in the class declaration (with some exceptions for static const integral types in C++11 and later). The question states 'none' as correct, which is technically accurate for traditional C++ where these types require separate definition outside the class. However, modern C++ (C++11 and later) does allow inline initialization for static const members of integral types, and constexpr static members. The question appears to be testing older C++ rules.
A
Correct answer
Explanation
JFC correctly stands for Java Foundation Classes. It's a graphical framework for building Java GUIs, which includes Swing, AWT, and Java 2D. The True option correctly identifies this GUI framework.
-
"X extends Y" is correct if and only if X is a class and Y is an interface
-
"X extends Y" is correct if and only if X is an interface and Y is a class
-
"X extends Y" is correct if X and Y are either both classes or both interfaces
-
"X extends Y" is correct for all combinations of X and Y being classes and/or interfaces
C
Correct answer
Explanation
In Java, the 'extends' keyword can only be used when both X and Y are classes (class inheritance), or when both X and Y are interfaces (interface inheritance). A class extends another class, and an interface extends another interface. A class implements an interface, not extends it.
-
Object-
-
Work-
-
@baseclass
-
Data-
C
Correct answer
Explanation
In Pega, class groups are directly inherited from @baseclass, which is the ultimate parent class in the Pega class hierarchy. All classes and class groups ultimately trace their inheritance back to @baseclass, making it the fundamental root of the class structure.
-
Object-
-
Work-
-
@baseclass
-
Data-
C
Correct answer
Explanation
In Pega, class groups are directly inherited from @baseclass, which is the ultimate parent class in the Pega class hierarchy. All classes and class groups ultimately trace their inheritance back to @baseclass, making it the fundamental root of the class structure.
-
Object-
-
Work-
-
@baseclass
-
Data-
C
Correct answer
Explanation
In Pega, class groups are directly inherited from @baseclass, which is the ultimate parent class in the Pega class hierarchy. All classes and class groups ultimately trace their inheritance back to @baseclass, making it the fundamental root of the class structure.
-
Object-
-
Work-
-
@baseclass
-
Data-
C
Correct answer
Explanation
In Pega, class groups are directly inherited from @baseclass, which is the ultimate parent class in the Pega class hierarchy. All classes and class groups ultimately trace their inheritance back to @baseclass, making it the fundamental root of the class structure.
-
Object-
-
Work-
-
@baseclass
-
Data-
C
Correct answer
Explanation
In Pega, class groups are directly inherited from @baseclass, which is the ultimate parent class in the Pega class hierarchy. All classes and class groups ultimately trace their inheritance back to @baseclass, making it the fundamental root of the class structure.
-
As a replacement for the Pega supplied Work- classes
-
To contain specialized rules used by the application.
-
As a temporary placeholder for a Pega purchased Framework
-
To contain rules that will be used across the enterprise.
D
Correct answer
Explanation
The framework class layer contains common, reusable rules designed to be shared and extended across the entire enterprise or multiple implementations. It does not replace Pega standard work classes, nor is it a temporary placeholder or intended solely for localized, specialized rules.
B
Correct answer
Explanation
A cover and its covered work objects must belong to the same class group as they are structurally linked - the cover object encapsulates related covered cases. They cannot be in different class groups.
-
It can extend exactly one class and implement exactly one interface.
-
It can extend exactly one class and can implement multiple interfaces.
-
It can extend exactly one class or implement exactly one interface.
-
It can implement multiple interfaces regardless of whether it also extends a class.
C
Correct answer
Explanation
Anonymous inner classes can either extend one class OR implement one interface, but not both simultaneously. This is a syntax limitation - you cannot write 'new MyClass() implements MyInterface { }' or extend multiple classes.
-
Boo f = new Boo(24) { };
-
Boo f = new Bar() { };
-
Bar f = new Boo(String s) { };
-
Boo f = new Boo.Bar(String s) { };
B
Correct answer
Explanation
The correct syntax creates an anonymous subclass of Bar (which extends Boo). Option A is wrong because 24 is not a String. Option C is syntactically invalid. Option D is wrong syntax for anonymous class creation. Option B correctly instantiates Bar and makes it anonymous.
-
It must be marked final.
-
It can be marked abstract.
-
It can be marked public.
-
It can be marked static.
B
Correct answer
Explanation
Method-local inner classes CAN be marked abstract - they are defined inside a method like any other class and support abstract modifiers. They cannot be static (static inner classes are only class-level) and cannot be public (only default and private access are allowed for method-local classes).
-
Runnable r = new Runnable() { };
-
Runnable r = new Runnable(public void run() { });
-
Runnable r = new Runnable { public void run(){}};
-
System.out.println(new Runnable() {public void run() { }});
D
Correct answer
Explanation
This statement compiles because the anonymous inner class correctly implements the required run method of the Runnable interface. The other options fail due to syntax errors, such as missing parenthesis in option 3 or passing Java code as an argument in option 2, or missing implementation of the abstract run method in option 1.