Object Oriented Programming in Java -
Internal Assessment II (April 2025)
PART A (10 x 1 = 10 Marks)
1. b) Private member of subclass
2. b) class B extends A
3. c) thrown
4. a) Runnable
5. b) To wait for a thread to finish execution
6. a) isAlive()
7. b) catch
8. d) Not accessible in its subclass
9. a) Start a new thread
10. FALSE
PART B (10 x 2 = 20 Marks)
11. Structure of predefined packages in Java:
java
├── lang
├── util
├── io
├── net
├── awt
└── sql
12. Overloading vs Overriding:
- Overloading: Same method name with different parameters (same class).
- Overriding: Redefine method from superclass (same parameters).
13. Divide by zero error handling:
try {
int x = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero.");
}
14. Multiplication table program:
import java.util.Scanner;
public class MultiplicationTable {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();
for (int i = 1; i <= 10; i++) {
System.out.println(num + " x " + i + " = " + (num * i));
}
}
}
15. Try-catch-throw example:
public class Example {
public static void main(String[] args) {
try {
int a = 5 / 0;
} catch (ArithmeticException e) {
System.out.println("Exception: " + e);
}
}
}
16. Steps for creating threads:
1. Extend Thread class or implement Runnable.
2. Override run().
3. Create thread object.
4. Call start().
17. isAlive() checks thread status. join() waits for thread completion.
18. Thread vs Runnable:
- Thread: Extends Thread class, more memory.
- Runnable: Implements Runnable interface, more flexible.
PART C (2 x 10 = 20 Marks)
19. Multithreading vs Multitasking:
- Multitasking: Multiple programs run simultaneously.
- Multithreading: Multiple threads in same program.
Thread class example:
class MyThread extends Thread {
public void run() {
System.out.println("Thread is running...");
}
public static void main(String[] args) {
MyThread t1 = new MyThread();
t1.start();
}
}
20. Inheritance and types:
- Types: Single, Multilevel, Hierarchical.
- Java doesn't support multiple inheritance directly.
Example:
class Animal {
void sound() {
System.out.println("Animal sound");
}
}
class Dog extends Animal {
void bark() {
System.out.println("Dog barks");
}
public static void main(String[] args) {
Dog d = new Dog();
d.sound();
d.bark();
}
}
21. Exception Handling in Java:
- try, catch, finally, throw, throws are used.
Example:
public class ExceptionExample {
public static void main(String[] args) {
try {
int a = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero.");
} finally {
System.out.println("Finally block executed.");
}
}
}
22. Thread States:
New → Runnable → Running → Blocked/Waiting → Terminated
- New: Thread object created
- Runnable: Ready to run
- Running: Executing
- Waiting/Blocked: Paused
- Terminated: Execution finished