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

Java 2 Marks Questions

Inheritance in object-oriented programming allows a child class to inherit properties and methods from a parent class, promoting code reuse. Types of inheritance include single, multilevel, hierarchical, multiple (via interfaces), and hybrid. Additionally, the document discusses interfaces, exception handling, the main thread, thread creation methods, thread priority, and the benefits of multithreading.

Uploaded by

prathaplisa
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)
17 views2 pages

Java 2 Marks Questions

Inheritance in object-oriented programming allows a child class to inherit properties and methods from a parent class, promoting code reuse. Types of inheritance include single, multilevel, hierarchical, multiple (via interfaces), and hybrid. Additionally, the document discusses interfaces, exception handling, the main thread, thread creation methods, thread priority, and the benefits of multithreading.

Uploaded by

prathaplisa
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
You are on page 1/ 2

1.

Define Inheritance:

Inheritance is an object-oriented programming feature where one class (child) can inherit the

properties and methods of another class (parent), promoting code reuse and hierarchy.

2. What are the Types of Inheritance?

- Single Inheritance

- Multilevel Inheritance

- Hierarchical Inheritance

- Multiple Inheritance (via interfaces in Java)

- Hybrid Inheritance

3. How to define an Interface?

In Java, an interface is defined using the "interface" keyword:

interface Drawable {

void draw();

4. Difference between Interface and Abstract Classes:

- Interface: Only abstract methods (Java 8+ allows default/static methods). No constructor.

- Abstract Class: Can have both abstract and non-abstract methods. Can have constructors and

variables.

5. Define Exception Handling Techniques with Example:

Exception handling manages runtime errors using try, catch, finally, and throw:

try {

int a = 5/0;

} catch (ArithmeticException e) {

[Link]("Cannot divide by zero");

}
6. What is the Main Thread with Example:

The main thread is the first thread started when a Java program begins:

public class Main {

public static void main(String[] args) {

[Link]([Link]().getName());

7. Characteristics of the Main Thread:

- It starts automatically in every Java program.

- It has the highest priority by default (priority 5).

- It runs until all non-daemon threads finish.

8. Comparison of Methods in Creation of New Threads:

- Extending Thread class: class MyThread extends Thread

- Implementing Runnable: class MyThread implements Runnable

Runnable is preferred for flexibility and multiple inheritance.

9. Range of Thread Priority:

Java thread priorities range from 1 (MIN_PRIORITY) to 10 (MAX_PRIORITY), with 5

(NORM_PRIORITY) as default.

10. What are Multithreading and its Benefits?

Multithreading is the ability of a CPU to execute multiple threads simultaneously.

Benefits:

- Better CPU utilization

- Faster execution

- Resource sharing

- Responsive UI in GUI apps

You might also like