0% found this document useful (0 votes)
7 views2 pages

Java Exam Answers and Concepts Explained

The document contains Java exam answers covering various topics such as thread lifecycle, object-oriented concepts, and exception handling. Key points include the distinction between static and instance blocks, the differences between interfaces and abstract classes, and the principles of overloading, overriding, and hiding. It also discusses the platform-independent nature of Java and the immutability of String objects.

Uploaded by

immahima169
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Java Exam Answers and Concepts Explained

The document contains Java exam answers covering various topics such as thread lifecycle, object-oriented concepts, and exception handling. Key points include the distinction between static and instance blocks, the differences between interfaces and abstract classes, and the principles of overloading, overriding, and hiding. It also discusses the platform-independent nature of Java and the immutability of String objects.

Uploaded by

immahima169
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Exam Answers

Q1. Attempt all questions: (1x5 = 5 Marks)

a) Lifecycle of thread:

- New, Runnable, Running, Blocked/Waiting, Terminated

b) Laptop as an object:

- Attributes: RAM, processor

- Methods: turnOn(), shutDown()

c) Narrowing, Widening, Upcasting:

- Narrowing: double d = 10.5; int i = (int) d;

- Widening: int i = 10; double d = i;

- Upcasting: Dog d = new Dog(); Animal a = d;

d) Platform-independent nature of Java:

- Java bytecode runs on JVM which is platform-independent.

e) Static and instance blocks:

- Static block runs once when class loads.

- Instance block runs with every object.

Q2. Attempt all questions (2.5x4 = 10 Marks)

a) i) Object initialization:

- new keyword, constructor, clone, factory method

ii) Interfaces vs abstract class:

- Supports multiple inheritance, flexibility, contract definition

b) i) public static void main(String[] args):

- public: accessible, static: no object, void: no return, main: entry, String[]: args

ii) No multiple inheritance:


- Java uses interfaces to achieve it

c) i) Overloading, Overriding, Hiding:

- Overloading: same name, diff params

- Overriding: subclass redefines

- Hiding: static methods

ii) Variable types:

- Instance: object-level

- Static: class-level

- Local: method-level

- final: constant

d) i) super() in inheritance:

- Calls parent class constructor

ii) Immutability of String:

- String objects cannot be modified after creation

Q3. Attempt any one (5x1 = 5 Marks)

i) Creating Threads:

- Extend Thread or implement Runnable

ii) Exception Handling:

- try-catch block

- Checked: compile-time (IOException)

- Unchecked: runtime (ArithmeticException)

You might also like