WorksheetsISB16003 OOP - Final Revision (1-4)
Total questions: 102
Worksheet time: 59mins
REVISION 1
What does CPU stand for in computing?
Central Processing Unit
Computer Personal Unit
Control Programming Unit
Central Programming Unit
Which of the following is a high-level programming language?
Assembly
Java
Binary
Machine Code
What is the correct file extension for a Java source file?
.jav
.java
.class
.jar
Which component is responsible for translating Java code to bytecode?
JVM
Compiler
Assembler
IDE
Which of the following is NOT a primitive data type in Java?
int
String
boolean
double
In Java, what keyword is used to define a class?
define
struct
class
object
Which of the following is used for single-line comments in Java?
/* comment */
// comment
# comment
<!--comment-->
Which method serves as the entry point for a Java program?
public class main()
static void Main()
public static void main(String[] args)
main()
Which statement correctly declares an integer variable in Java?
int x = "10";
int x = 10;
integer x = 10;
num x = 10;
What will the expression 5 / 2 return in Java?
2.5
3
2
2.0
What does the System.out.println() function do?
Reads user input
Declares a variable
Prints output to the console
Terminates the program
Which of these is a valid identifier in Java?
1stValue
first-value
firstValue
class
Which data type should be used to store true/false values?
char
int
bool
boolean
What is the purpose of the import statement in Java?
To define new classes
To include standard libraries
To start execution
To declare variables
What is the result of 10 % 3 in Java?
3
1
0
2
Which of the following best describes the role of the Java Virtual Machine (JVM)?
Converts bytecode to machine code
Compiles Java to binary
Executes only .jar files
Manages file input/output
Which statement about Java memory management is true?
Java uses manual memory allocation
The programmer must delete objects
Java uses automatic garbage collection
Memory is managed using pointers
Given: int x = 5; x += x++ + ++x;, what is the final value of x?
11
16
17
12
Which of the following is not true about Java bytecode?
It's platform-independent
It runs directly on hardware
It's interpreted by the JVM
It's the compiled version of Java source code
What will the following code output?
int a = 5, b = 2;
System.out.println(a++ * ++b);
10
12
15
14
Case Study: E-Learning Assignment Submission System (10 marks)
Scenario:
An E-Learning platform manages assignments submitted by students.
• A base class Assignment contains assignmentId, title, and submissionDate.
• Subclasses include EssayAssignment and CodingAssignment.
• Each assignment type has its own grading logic using a method gradeAssignment().
• Lecturers grade assignments through a list of Assignment objects.
• Assignment data must not be modified after submission.
• Late submission rules differ between assignment types.
1. Different grading logic in each subclass is an example of:
A. Abstraction
B. Method Overloading
C. Method Overriding
D. Encapsulation
2. To ensure all assignment types implement gradeAssignment(), the method should be declared as:
A. final
B. static
C. abstract
D. private
3. Preventing modification of assignmentId after object creation can be achieved using:
A. static
B. final
C. protected
D. volatile
4. Processing different assignment types using a single Assignment reference demonstrates:
A. Inheritance
B. Encapsulation
C. Polymorphism
D. Aggregation
5. Late submission rules differ per assignment type. This design supports:
A. Single Responsibility Principle
B. Class-Specific Behavior
C. Interface Segregation
D. Data Hiding
REVISION 2
Which of the following modifiers limits access to within the class only?
public
protected
default
private
Encapsulation is implemented in Java by:
Declaring attributes as public
Declaring attributes as private and providing getters/setters
Using abstract classes only
Using interfaces
Which of these is not an access modifier in Java?
protected
default
private
internal
In UML, an abstract class name is written in:
Bold
Italics
Underline
Uppercase
In Java, if no access modifier is specified, the default level is:
public
private
protected
package-private (default)
Which keyword is used to inherit a class in Java?
inherit
derive
extends
implements
A subclass can access which members of its superclass?
private only
protected and public
default only
all members including private
Which of the following can be overridden?
final methods
private methods
static methods
public instance methods
Which of these best describes inheritance?
A method hiding mechanism
A way to overload constructors
A way to create multiple constructors
A mechanism to derive new classes from existing ones
The keyword super is used for:
Accessing child class attributes
Instantiating superclass
Calling superclass constructor or method
Referring to current object
Which of the following is an example of dynamic binding?
Method overloading
Method overriding
Static methods
Constructors
What is printed? class A { void show() { System.out.println("A"); } } class B extends A { void show() { System.out.println("B"); } } public class Test { public static void main(String[] args) { A obj = new B(); obj.show(); } }
A
B
Compile-time error
Runtime error
What is method overloading?
Changing method name in subclass
Using same method name with different parameters in same class
Overriding a method with new return type
Hiding methods in subclass
Which of the following is resolved at compile-time?
Method Overriding
Dynamic Method Dispatch
Method Overloading
Abstract method call
Which of the following represents polymorphism?
One interface, many implementations
Static variable
Final class
Protected methods
Static methods can access:
Only static variables
Both static and instance variables
Only instance variables
Non-static methods
Final variables:
Can be modified in subclass
Can be initialized once only
Are always static
Cannot be used in loops
Which is true about static methods?
Can call instance methods
Can use "this"
Can be overridden
Belong to the class
Abstract methods:
Must be static
Must have a body
Cannot exist in a non-abstract class
Can be private
A class that contains at least one abstract method must be:
Static
Final
Public
Abstract
Which is true about Java interfaces?
Can contain constructors
Can contain method implementations
Can contain only abstract methods and constants
Cannot be implemented by classes
A class can implement:
One interface only
Multiple classes
Multiple interfaces
One class and one interface only
Which line is correct for interface implementation?
class A extends B, implements C
class A implements B, C
interface A extends class B
class A implements interface B
What relationship does "implements" indicate in Java?
is-a
has-a
is-a-kind-of
uses-a
Which of the following simulates multiple inheritance?
Abstract classes
Method overloading
Interfaces
Static methods
Case Study: Online Banking Account Management System (10 marks)
Scenario: An Online Banking System manages different types of bank accounts.
• There is a base class BankAccount with attributes accountNumber, holderName, and balance.
• Subclasses include SavingsAccount and CurrentAccount.
• SavingsAccount applies interest, while CurrentAccount allows overdraft up to a limit.
• Each account type implements a method calculateMonthlyCharges().
• The system processes a list of BankAccount objects to calculate charges.
• Account details must be protected from direct modification.
1. Implementing calculateMonthlyCharges() differently in SavingsAccount and CurrentAccount demonstrates:
A. Encapsulation
B. Method Overriding
C. Composition
D. Aggregation
2. To prevent direct access to the balance attribute, it should be declared as:
A. public
B. protected
C. private
D. static
3. Storing different account types in a single list of BankAccount objects relies on:
A. Inheritance
B. Encapsulation
C. Polymorphism
D. Abstraction
4. If BankAccount should not be instantiated directly, how should it be defined?
A. final class
B. interface
C. abstract class
D. static class
5. The overdraftLimit attribute exists only in CurrentAccount. This is an example of:
A. Data Hiding
B. Class-Specific Behavior
C. Method Overloading
D. Multiple Inheritance
REVISION 3
Which keyword is used to implement encapsulation?
public
protected
private
static
What is true about a static variable?
It belongs to each object separately
It is reinitialized for every new object
It is shared across all instances
It can only be used in interfaces
Which of the following can access protected members?
Any class
Same package and subclasses
Only the defining class
Subclasses in different packages only
A method defined as final:
Can be overridden
Cannot be inherited
Cannot be overridden
Must be abstract
What does the super() keyword do in a subclass constructor?
Calls the same class constructor
Calls an interface method
Calls superclass constructor
Access private members of parent class
Which of the following is true about abstract classes?
Can be instantiated
Can have abstract and concrete methods
Must only contain abstract methods
Must implement an interface
What is the purpose of an interface in Java?
To create constants
To enforce multiple inheritance behavior
To hold only data
To create a final class
Which of the following is true for static methods?
They can use instance variables
They can override non-static methods
They can only access static members
They must return void
What keyword is used to prevent class inheritance?
static
final
abstract
protected
What is the correct access level for members accessible in the same package only?
private
protected
default
public
Which feature allows method calls to decide at runtime?
Static binding
Method overloading
Method overriding
Constructor chaining
What happens if a subclass does not implement all abstract methods?
It will compile
It must be declared abstract
It can override them later
It inherits them by default
How many interfaces can a class implement?
Only one
Two
Multiple
None
Which keyword allows access to superclass methods/constructors?
base
parent
super
this
What type of inheritance is not allowed in Java?
Multilevel
Hierarchical
Multiple (with classes)
Single
Which method is used to convert an object into a string representation?
convertToString()
toString()
stringFormat()
getString()
What is a UML class diagram used for?
Testing a program
Running a program
Describing system structure
Debugging
Which polymorphism is applied when method signature is same in parent and child?
Overloading
Early binding
Overriding
Static binding
What is the use of "this" keyword?
Refer to a static method
Refer to the current object
Refer to a superclass
Refer to global variable
Which one is true about interface members?
Can be private
Can have implementation
Must be abstract or static final
Can have constructors
What will be the output?
public class Circle {
static int numberOfObjects = 0;
public Circle() {numberOfObjects++;}
public static int getCount() {return numberOfObjects;}
public static void main(String[] args) {
Circle c1 = new Circle();
Circle c2 = new Circle();
System.out.println(Circle.getCount());
}
}
1
2
0
Error
Which of the following declarations is correct for an abstract method?
public void run() {}
public abstract void run();
public abstract void run() {}
abstract run();
23. What will this print?
abstract class Animal { abstract void sound(); }
class Cat extends Animal { void sound() { System.out.println("Meow"); } }
public class Test { public static void main(String[] args) { Animal a = new Cat(); a.sound(); } }
A. Meow
B. Bark
C. Error
D. No output
24. Which is a valid way to access a static method?
A. obj.method()
B. ClassName.method()
C. this.method()
D. super.method()
25. Why can't static methods use this?
A. Because it’s private
B. Because this refers to an instance, but static methods do not belong to an instance
C. Because it’s undefined
D. Because it’s final
26. Code output?
interface Flyer { void fly(); }
class Bird implements Flyer { public void fly() { System.out.println("Bird is flying"); } }
public class Test { public static void main(String[] args) { Flyer f = new Bird(); f.fly(); } }
A. Bird is flying
B. Error
C. Nothing
D. Interface cannot be used
27. Trace the output:
class A { public void display() { System.out.println("A"); } }
class B extends A { public void display() { System.out.println("B"); } }
public class Test { public static void main(String[] args) { A obj = new B(); obj.display(); } }
A. A
B. B
C. AB
D. Error
28. Which is true about interfaces?
A. They allow constructors
B. They can implement classes
C. They allow multiple inheritance
D. They cannot be used polymorphically
29. What happens if a method in subclass has the same signature as parent but different return type?
A. It's valid overriding
B. Compile-time error
C. Runtime error
D. Treated as overload
30. What’s the result?
abstract class Vehicle { int year = 2020; abstract void display(); }
class Car extends Vehicle { void display() { System.out.println("Car made in " + year); } }
public class Test { public static void main(String[] args) { Vehicle v = new Car(); v.display(); } }
A. Car made in 2020
B. Vehicle
C. Error
D. Car
REVISION 4
What happens if an exception is not caught in a try block?
The program continues execution
The program goes to the finally block and continues
The program terminates abnormally
The JVM retries the failed operation
Which of the following exceptions is checked?
ArithmeticException
IOException
NullPointerException
ArrayIndexOutOfBoundsException
Which keyword is used to declare that a method might throw an exception?
throw
throws
catch
finally
What is the output of this code? int[] x = new int[2]; System.out.println(x[5]);
0
Compilation error
java.lang.ArrayIndexOutOfBoundsException
java.lang.NullPointerException
What is the superclass of all errors and exceptions in Java?
Exception
Error
RuntimeException
Throwable
The finally block is executed:
Only when an exception is thrown
Only if no exception is thrown
Always
Only if the catch block is executed
What will happen if both catch and finally blocks contain return statements?
The catch block’s return is used
The finally block’s return is used
Compilation error
Unpredictable behavior
What type of exception is NullPointerException?
Checked
Unchecked
Logic error
Compile-time error
Identify the output:
try {int a = 10 / 0; }
catch (ArithmeticException e) { System.out.println("Catch"); }
finally {System.out.println("Finally");}
Catch
Finally
Catch Finally
Compilation error
Which method provides the most detailed information about an exception stack?
toString()
getMessage()
printStackTrace()
getCause()
Which of the following is not a runtime exception?
NullPointerException
ArithmeticException
IOException
ArrayIndexOutOfBoundsException
What happens when you use throw without an exception object?
Nothing
Compilation error
Runtime error
Default exception is thrown
In the following code, what exception will be thrown?
String[] arr = {"Java", "Network", "Maths"};
for(int i = 0; i < 4; i++){System.out.println(arr[i]); }
NullPointerException
ArrayIndexOutOfBoundsException
ClassCastException
No exception
Which statement is true about throw and throws?
Both are used for throwing exceptions
throw is used in method header; throws in the body
throw is used to throw; throws is used to declare
throws is used for custom exceptions only
What is the correct way to create a custom exception?
class MyException extends Throwable
class MyException extends RuntimeException
class MyException extends Exception
class MyException implements Exception
How do you prevent a method from being overridden?
Declare it as static
Declare it as abstract
Declare it as final
Declare it as public
Which of the following is NOT allowed in an interface?
public abstract methods
static final variables
private constructors
Implemented by classes
Which is true about constructors in inheritance?
Superclass constructor is inherited
Subclass must define all constructors
Superclass constructor is called explicitly or implicitly
Superclass constructor is ignored
What happens if you try to override a static method?
It’s allowed
It causes a compile error
It hides the method, not override
It overrides normally
What does the implements keyword do?
Inherit a class
Implement a static method
Adopt an interface’s method contracts
None of the above
What is true about the following class definition? public final class Bank { ... }
It can be subclassed
It cannot be instantiated
It cannot be subclassed
It must be abstract
What is the purpose of super() in a constructor?
Initializes local variables
Calls current class constructor
Calls superclass constructor
Binds to abstract class
Which of the following is valid multiple inheritance using interface?
public class Plane extends Vehicle, Animal implements Flyer { ... }
Valid
Invalid due to multiple classes
Valid if Plane is abstract
Valid if Flyer is abstract
What does the abstract keyword imply for a method?
It must return void
It has implementation
It has no implementation and must be overridden
It can be private
What is printed?
Vehicle v = new Aeroplane(200);
v.DisplayVehicleDetails();
Compile-time error
Aeroplane details including 200 passengers
Vehicle
Nothing
