java
java
• Method Overloading: Involves defining multiple methods in the same class with the same name
but different parameter lists. It is an example of compile-time polymorphism.
• Method Overriding: Occurs when a subclass provides a specific implementation for a method
already defined in its parent class. It is an example of runtime polymorphism.
Polymorphism
Compile-time Runtime
Type
Classpath is an environment variable that tells the Java compiler and JVM where to look for user-defined
classes and packages.
1. Why is Java Machine Independent?
Java programs are compiled into bytecode, which the JVM interprets on any platform.
Classpath is an environment variable or command-line argument in Java that specifies the location of
user-defined classes and packages. It tells the Java compiler and JVM where to look for class files.
Utility of Classpath:
1. Encapsulation:
Bundling data and methods that operate on the data within a class, while restricting direct
access to some components.
2. Inheritance:
Enabling a class (subclass) to inherit fields and methods from another class (superclass).
3. Polymorphism:
Allowing a single interface to represent different types. Achieved via method overloading
(compile-time) and overriding (runtime).
4. Abstraction:
Hiding implementation details while exposing only the essential features.
5. Reusability:
Code can be reused across different parts of a program via inheritance and classes.
Functionality of JVM:
• Abstraction focuses on hiding implementation details and only exposing the essential
functionality.
Example: Abstract classes and interfaces.
• Encapsulation is the mechanism of bundling data and methods together and restricting direct
access.
The this keyword in Java refers to the current instance of a class. It is used to:
1. Distinguish between instance variables and parameters with the same name.
The main method in Java is static to allow the JVM to invoke it without creating an instance of the class.
This is necessary because:
2. A static method belongs to the class, not an instance, enabling JVM to execute it directly.