OBJECT-ORIENTED
PROGRAMMING WITH
JAVA
Techno Main Salt Lake | CA2
Nirmalya Nandi | Roll: 13071025056 | Paper Code: MCAN-203
INTRODUCTION TO JAVA & OOP
Java is a high-level, platform-independent programming language that enables developers to write code once and run it anywhere. Its robust
implementation of Object-Oriented Programming (OOP) principles makes it ideal for building scalable, maintainable applications.
ENCAPSULATION INHERITANCE
Bundling data and methods together while restricting direct access Creating new classes from existing ones, promoting code reuse and
to internal details hierarchical relationships
POLYMORPHISM ABSTRACTION
Objects of different classes can be treated uniformly through Hiding complex implementation details and showing only essential
common interfaces features
SCOPE AND USE OF ACCESS MODIFIERS
Access modifiers control the visibility and
accessibility of classes, methods, and variables.
They enable data hiding by restricting access to
sensitive components while exposing only
what's necessary for external interaction.
FOUR ACCESS LEVELS
Private: Accessible only within the same
class
Default: Accessible within the package
Protected: Package access plus child
classes
Public: Accessible from anywhere
METHOD OVERLOADING: CONCEPT & RULES
Method overloading implements compile-time polymorphism by allowing multiple methods with the same name but different parameter lists. The
compiler determines which method to invoke based on the arguments passed during the method call.
01 02 03
SAME METHOD NAME DIFFERENT PARAMETERS RETURN TYPE IRRELEVANT
Identifiers must match exactly Vary by number, type, or order Cannot overload by return type alone
public class Calculator {
public int add(int a, int b) {
return a + b;
}
public int add(int a, int b, int c) {
return a + b + c;
}
public double add(double a, double b) {
return a + b;
}
}
KEY RESTRICTIONS IN
METHOD OVERLOADING
Important: Changing only the return type without modifying the parameter
list does NOT constitute method overloading and will result in a compile-time
error.
❌ INVALID ✅ VALID
OVERLOADING OVERLOADING
public int getValue() { public int getValue() {
return 42; return 42;
} }
public double getValue() { public int getValue(int
return 42.0; multiplier) {
} return 42 * multiplier;
}
Compile error: Cannot change return
type alone Valid: Different parameter list
PURPOSE AND APPLICATIONS OF FINAL
The final keyword provides immutability and prevents modification at various levels of your program. It's a powerful tool for creating constants,
preventing inheritance, and maintaining data integrity.
1 2 3
FINAL VARIABLES FINAL METHODS FINAL CLASSES
Creates constants that cannot be Prevents method overriding by subclasses, Prevents inheritance entirely, no class can
reassigned after initialization ensuring consistent behavior extend it
final double PI = 3.14159; public final void display() { public final class
final String GREETING = "Hello, [Link]("Cannot MathConstants {
World!"; override this method"); public static final double PI =
} 3.14159;
}
PURPOSE AND APPLICATIONS OF STATIC
The static keyword belongs to the class itself rather than to any specific instance. Static members are created only once when the class is loaded into
memory, making them efficient for shared data and utility methods.
KEY CHARACTERISTICS
Memory allocated only once during class loading
Shared across all instances of the class
Accessible without creating class instances
Can be accessed using [Link] syntax
COMMON USES
Static variables for shared data
Static methods for utility functions
Static blocks for initialization logic
Constants when combined with final
STATIC VS. FINAL: A PRACTICAL
COMPARISON
Feature
SUMMARY & KEY RESTRICTIONS
METHOD OVERLOADING FINAL VARIABLES FINAL METHODS
Cannot rely on return type alone to Cannot reassign values after initialization Cannot be overridden by subclasses
distinguish methods
final int MAX_VALUE = 100; public final void display() { }
// Invalid: Only return type MAX_VALUE = 200; // Compile // Subclass cannot override
differs error! display()
public int getValue() { return 1;
}
public double getValue() {
return 1.0; }
FINAL CLASSES STATIC CONTEXT
Cannot be extended or inherited Cannot access non-static members
directly or use this or super
public final class Utility { }
// Cannot create subclass of public static void method() {
Utility instanceVar = 10; // Error!
[Link] = 5; // Error!
}
CONCLUSION
Understanding these fundamental concepts—access modifiers, method overloading,
final, and static—empowers developers to create robust, secure, and memory-efficient
class-level designs in Java. These principles form the foundation for building
professional-grade applications.
THANK YOU