0% found this document useful (0 votes)
2 views

Java Concepts Answers

The document explains key concepts in Java, including JVM, JDK, and JRE, as well as the differences between HAS-A and IS-A relationships. It covers polymorphism, method binding, method overloading, and method overriding, along with their rules and distinctions. Additionally, it defines abstract classes and methods, highlighting when to use them in Java programming.

Uploaded by

cm23jm2984
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)
2 views

Java Concepts Answers

The document explains key concepts in Java, including JVM, JDK, and JRE, as well as the differences between HAS-A and IS-A relationships. It covers polymorphism, method binding, method overloading, and method overriding, along with their rules and distinctions. Additionally, it defines abstract classes and methods, highlighting when to use them in Java programming.

Uploaded by

cm23jm2984
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/ 3

1. What is JVM, JDK, and JRE?

- JVM (Java Virtual Machine): It runs Java bytecode and makes Java platform-independent.

- JDK (Java Development Kit): A package that includes JRE + tools for Java development (compiler,

debugger, etc.).

- JRE (Java Runtime Environment): It provides environment to run Java programs. Includes JVM +

libraries.

2. Differentiate between HAS-A and IS-A relationship?

- IS-A: Represents inheritance. A child class IS-A parent class (e.g., Dog IS-A Animal).

- HAS-A: Represents composition. A class contains another class (e.g., Car HAS-A Engine).

3. How to avoid Diamond Problem in Java?

- Java uses interfaces to avoid diamond problem. Since Java doesn't support multiple inheritance

with classes, interfaces are used and ambiguity is resolved using default methods.

4. What is polymorphism?

- Polymorphism means one thing behaves in different ways. In Java, it can be compile-time (method

overloading) or run-time (method overriding).

5. What is method binding?

- Its the process of connecting a method call to its code.

- Static binding: Done at compile time (e.g., method overloading).

- Dynamic binding: Done at runtime (e.g., method overriding).

6. What is compile-time polymorphism?

- Also called method overloading. Same method name with different parameters.
7. What is run-time polymorphism?

- Also called method overriding. Method in subclass overrides parent class method at runtime.

8. What is method overloading?

- Same method name with different parameters in the same class.

9. What is method overriding?

- Redefining a method of the parent class in the child class.

10. Rules for method overloading:

- Methods must differ in number or type of parameters.

11. Rules for method overriding:

- Same method name, return type, and parameters.

- Child class access level must not be more restrictive.

- Only inherited methods can be overridden.

12. Difference between overloading and overriding:

- Overloading: Same class, different parameters, compile-time.

- Overriding: Subclass, same method signature, run-time.

13. What is an abstract class?

- A class that can't be instantiated and may contain abstract methods.

14. What is an abstract method?

- A method without a body that must be implemented by subclasses.


15. When should a class be abstract?

- When we want to define a common structure and enforce some methods to be implemented in

child classes.

You might also like