WorksheetsObject-Oriented Programming Concepts Worksheet (Transcribed)
Total questions: 113
Worksheet time: 57mins
A hospital system creates patient objects dynamically at runtime. Where are these objects stored?
Heap memory
Stack memory
Register
Method area
A banking app must not allow interest rate value to change once set. Which keyword enforces this?
final
static
abstract
protected
A class is designed only to be inherited and not instantiated. Which type is suitable?
Abstract class
Interface
Package
Enum
A billing system defines calculateBill() with different parameter types. Which concept is used?
Method overloading
Method overriding
Encapsulation
Polymorphism
An ATM software hides internal cash calculation logic from users. Which principle is applied?
Encapsulation
Inheritance
Polymorphism
Abstraction
A weather system stores temperature readings of 31 days. Which structure is efficient?
Array
Single variable
Interface
Class
A chat server updates message content frequently. Which class should be used?
StringBuilder
String
Character
Array
A gaming app uses different attack behaviors for different characters at runtime. Which concept supports this?
Polymorphism
Inheritance
Encapsulation
Abstraction
A login module must run validation at least once before checking condition. Which loop fits?
do-while
while
for
switch
A payroll system extends Employee class to Manager class. Which keyword is used?
extends
implements
super
this
A project organizes related classes into logical folders. Which feature is used?
Package
Interface
JVM
JRE
A base reference calls a subclass method at runtime. Which binding occurs?
Dynamic binding
Static binding
Method hiding
Constructor chaining
A utility class must not be inherited for security reasons. Which keyword is used?
final
static
native
transient
A finance app converts integer input to double automatically during calculation. What is this?
Type conversion
Inheritance
Polymorphism
Encapsulation
A drawing app forces all shapes to define draw(). Which is best?
Interface
Abstract class
Package
Final class
A menu-driven railway system has fixed options. Which structure is suitable?
switch
if
while
for
A subclass constructor executes after parent constructor. Which concept explains this?
Constructor chaining
Method overriding
Polymorphism
Static binding
A text editor modifies content frequently. Which class avoids extra object creation?
StringBuffer
String
Character
Array
An online service standardizes function names across modules. Which construct helps?
Interface
Package
JVM
Enum
A reporting tool allows different formats using same method name. Which concept is applied?
Method overriding
Method overloading
Encapsulation
Packages
A sensor system stores multiple readings and sums them. Which structure is best?
Array with loop
Single variable
A class should provide partial implementation and force remaining methods. Which is ideal?
Abstract class
Interface
Package
Final class
A class should follow a contract but share no code. Which is used?
Interface
Abstract class
Package
JVM
A compiler converts source to bytecode. Which tool performs this?
javac
JVM
JRE
JIT
A runtime environment executes bytecode. Which component handles this?
JVM
JDK
JIT
Compiler
A class contains variables and methods together. Which concept is used?
Encapsulation
Polymorphism
Abstraction
Inheritance
A class hides internal logic and exposes only essential features. Which principle applies?
Abstraction
Inheritance
Polymorphism
Encapsulation
An object reference changes behavior based on actual object type. Which concept?
Polymorphism
Encapsulation
Abstraction
Inheritance
A company groups payroll-related classes separately. Which feature supports this?
Packages
Interfaces
JVM
JRE
A program must ensure one-time execution before loop condition. Which loop?
do-while
while
for
switch
A program uses multiple constructors in a class. Which concept is this?
Constructor overloading
Method overriding
Polymorphism
Inheritance
A base class method is replaced in subclass. Which is applied?
Method overriding
Method overloading
Abstraction
Encapsulation
A real-time system selects method at runtime. Which mechanism?
Dynamic binding
Static binding
Method hiding
Constructor chaining
A utility method works for int and double inputs. Which concept is used?
Method overloading
Method overriding
Packages
Inheritance
A student system prevents class inheritance. Which keyword?
final
static
protected
abstract
A program runs same code on Windows and Linux. Which feature enables this?
Bytecode on JVM
Pointers
Native compiler
Hardware execution
A loop repeats until user enters correct input. Which loop is ideal?
do-while
for
if
switch
A program stores 2D marks list. Which structure is used?
Multidimensional array
Single array
Interface
Abstract class
A library app hides book ID from user. Which access control helps?
private
public
default
protected
A subclass uses parent variable. Which keyword accesses it?
super
this
static
final
A method accepts unlimited parameters. Which feature is used?
Varargs
Overloading
Overriding
Constructor
A program must prevent method modification. Which keyword is used?
final
static
A class inside another class improves modularity. Which is this?
Inner class
Interface
Package
Enum
A method is implemented directly inside argument. Which type is this?
Anonymous class
Inner class
Abstract class
Interface
A class belongs to predefined library. Which package contains it?
java.lang
java.io
java.sql
java.util
A program chooses among multiple fixed options. Which structure?
switch
for
while
if only
A compiler warns when method signature mismatch occurs. Which rule is violated?
Overriding rule
Overloading rule
Package rule
JVM rule
A program stores user details with attributes and behavior. Which structure is used?
Class
Interface
Package
Method
An app ensures data hiding from external access. Which principle?
Encapsulation
Abstraction
Polymorphism
Inheritance
A program avoids multiple inheritance of classes but allows behavior sharing. Which feature?
Interface
Abstract class
Package
JVM
A company application stores employee details and behavior together. Which construct is used?
Class
Interface
Package
Method
A mobile app restricts modification of configuration values. Which keyword ensures this?
final
static
protected
abstract
A framework forces subclasses to implement required methods but shares common logic. Which design fits?
Abstract class
Interface
Package
Enum
A graphics system defines draw() differently for Circle and Rectangle at runtime. Which concept applies?
Polymorphism
Inheritance
Encapsulation
Abstraction
A data analytics program stores daily sales values efficiently. Which structure is best?
Array
Single variable
Interface
Abstract class
A chat application modifies text continuously. Which class improves performance?
StringBuilder
String
Character
Array
A base reference calls overridden method of subclass. Which mechanism resolves this?
Dynamic binding
Static binding
Method hiding
Constructor chaining
A class prevents object creation but provides method definitions. Which is used?
Abstract class
Interface
Concrete class
Package
A hospital system groups doctor-related classes separately. Which feature helps?
Packages
JVM
JRE
Interface
A calculator supports add(int,int) and add(double,double). Which concept is used?
Method overloading
Method overriding
Polymorphism
Encapsulation
A security module blocks subclass creation for sensitive classes. Which keyword is used?
final
static
private
abstract
A payroll program executes the same code on Windows and Linux. Which feature enables this?
JVM bytecode execution
Native compiler
Pointer usage
Hardware execution
A menu-driven program executes at least once before condition check. Which loop suits?
do-while
while
A company stores matrix of monthly expenses. Which structure is used?
Multidimensional array
Single array
Interface
Abstract class
A method accepts unlimited number of arguments. Which feature is used?
Varargs
Overloading
Overriding
Constructor
A banking app hides account balance from external access. Which access modifier is suitable?
private
public
default
protected
A subclass accesses parent class variable. Which keyword is used?
super
this
static
final
A class is nested inside another class for better organization. Which type is this?
Inner class
Interface
Package
Enum
A method is implemented without creating a named class. Which type is used?
Anonymous class
Abstract class
Interface
Package
A program uses predefined core classes like String and Math. Which package contains them?
java.lang
java.util
java.io
java.sql
A system groups billing-related classes logically. Which feature helps?
Packages
Inheritance
Polymorphism
JVM
A base class method is replaced by subclass method. Which concept applies?
Method overriding
Method overloading
Encapsulation
Abstraction
A utility method handles both integer and float inputs. Which feature supports this?
Method overloading
Method overriding
Inheritance
Package
A loop repeats until valid input is entered. Which structure is ideal?
do-while
for
switch
if
A class prevents modification of its method. Which keyword is used?
final
static
native
volatile
A Java program chooses from multiple fixed menu options. Which structure is best?
switch
for
while
if only
A system stores user data and operations together. Which principle applies?
Encapsulation
Polymorphism
Abstraction
Inheritance
A system exposes only essential features and hides internal details. Which principle applies?
Abstraction
Inheritance
Polymorphism
Encapsulation
A base reference refers to derived object at runtime. Which concept is demonstrated?
Polymorphism
Inheritance
Abstraction
Encapsulation
A program ensures one-time initialization before loop execution. Which loop fits?
do-while
while
for
switch
A class contains multiple constructors with different parameters. Which concept is used?
Constructor overloading
Method overriding
Inheritance
Polymorphism
A drawing application forces shapes to define draw(). Which is suitable?
Interface
Abstract class
Package
Enum
A utility class should not be instantiated. Which keyword supports this?
abstract
static
native
transient
A student system converts int marks to double automatically. What is this?
Type conversion
Polymorphism
A system organizes reusable modules logically. Which feature helps?
Packages
Interface
JVM
Enum
A subclass calls parent constructor first. Which concept explains this?
Constructor chaining
Method hiding
Static binding
Polymorphism
A method executes based on actual object type at runtime. Which is this?
Dynamic binding
Static binding
Method hiding
Constructor chaining
A class should share code and force method implementation. Which design fits?
Abstract class
Interface
Package
Enum
A class should only define behavior contract. Which is best?
Interface
Abstract class
Package
JVM
A system must avoid name conflict across modules. Which feature helps?
Packages
Polymorphism
Inheritance
JVM
A real-time app selects implementation based on object type. Which concept applies?
Polymorphism
Encapsulation
Abstraction
Inheritance
A program prevents further inheritance of a class. Which keyword is used?
final
static
native
protected
A method accepts multiple inputs of same type. Which feature supports this?
Varargs
Overloading
Overriding
Constructor
A class hides its variables from outside world. Which modifier is used?
private
public
protected
default
A subclass uses parent class method directly. Which keyword is used?
super
this
static
final
A text editor frequently updates strings. Which class is best?
StringBuffer
String
Character
Array
A software enforces same method name across different classes. Which construct is used?
Interface
Abstract class
Package
JVM
A Java program must ensure at least one execution of loop. Which is used?
do-while
while
for
switch
A system groups utility classes logically. Which feature helps?
Packages
Polymorphism
Inheritance
JVM
A software system allows extension without modifying existing code. Which concept supports this?
Polymorphism
Encapsulation
Inheritance
Arrays
User authentication check: Consider the following Java code. class Test { public static void main(String[] args) { String user = "admin"; if(user == "admin") System.out.print("Login"); else System.out.print("Fail"); } } What is the program output?
Login
Fail
Runtime error
Compilation error
Banking balance update: Consider the following Java code. class Bank { int balance = 1000; void update(int balance){ balance = balance + 500; } public static void main(String[] args){ Bank b = new Bank(); b.update(b.balance); System.out.print(b.balance); } } What is printed?
1500
1000
500
Error
Hospital patient counter: Consider the following Java code. class Hospital { static int count = 0; Hospital(){ count++; } public static void main(String[] args){ new Hospital(); new Hospital(); System.out.print(count); } } What is the output?
0
1
2
Error
Online order processing: Consider the following Java code. class Order { public static void main(String[] args){ int x = 10; System.out.print(x++ + ++x); } } What is the output?
21
22
20
23
IoT sensor reading: Consider the following Java code. class Sensor { public static void main(String[] args){ int[] temp = {30,31,32}; System.out.print(temp[3]); } } What happens when the program runs?
32
31
ArrayIndexOutOfBoundsException
Compilation error
Game character attack: Consider the following Java code. class A { void attack(){ System.out.print("Punch"); } } class B extends A{ void attack(){ System.out.print("Kick"); } } public class Test{ public static void main(String[] args){ A obj = new B(); obj.attack(); } } What is printed?
Punch
Kick
PunchKick
Error
Railway ticket price: Consider the following Java code. class Ticket { static int price = 50; public static void main(String[] args){ Ticket t1 = new Ticket(); Ticket t2 = new Ticket(); t1.price = 100; System.out.print(t2.price); } } What is the output?
50
100
0
Error
Student marks: Consider the following Java code. class Marks { public static void main(String[] args){ int a = 5; int b = 2; System.out.print(a/b); } } What is printed?
2
2.5
3
Error
File processing: Consider the following Java code. class FileTest { public static void main(String[] args){ String s = "Java"; s.concat("World"); System.out.print(s); } } What is the output?
Java
JavaWorld
World
Error
Login attempts: Consider the following Java code. class Login { public static void main(String[] args){ int i = 0; do{ System.out.print(i); i++; }while(i<3); } } What does the program print?
012
123
0123
01
Cloud server counter: Consider the following Java code. class Server { static int x = 10; public static void main(String[] args){ Server s1 = new Server(); s1.x++; Server s2 = new Server(); s2.x++; System.out.print(x); } } What is the output?
10
11
12
13
Shopping cart. Consider the Java code: class Cart { public static void main(String[] args){ String s1 = "Shop"; String s2 = new String("Shop"); System.out.print(s1 == s2); } } Choose the correct output.
true
false
Shop
Error
ATM pin check. Consider the Java code: class ATM { public static void main(String[] args){ int pin = 1234; if(pin = 1234) System.out.print("Valid"); } } Choose the correct outcome for compilation/execution.
Valid
Invalid
Compilation error
Runtime error
