output_2
output_2
Jocelyn Chinatsira
September 2024
1
1.3 OOP in Java
Java is inherently designed as an object-oriented language, which means that
everything in Java is an object, except for the primitive data types. The OOP
paradigm is at the core of Java’s architecture, influencing its syntax, structure,
and best practices.
String color;
int
year;
void displayInfo() {
System.out.println(
"Color: "
+ color +
+ year);
2
1.3.3 Inheritance in Java
Java supports single inheritance through the use of the extends keyword. This
allows subclasses to inherit attributes and methods from a superclass. For
instance:
java
Copy
Explainclass ElectricCar extends Car {
int
batteryCapacity;
void displayBatteryInfo() {
System.out.println(
"Battery Capacity: "
+ batteryCapacity);
}
}
3
1.3.5 Abstraction in Java
Java uses abstract classes and interfaces to implement abstraction. An abstract
class cannot be instantiated and may contain abstract methods that are declared
without an implementation. Subclasses must provide implementations for these
methods, ensuring that a common interface is maintained.
java
Copy
Explain
abstract
System.out.println(
"Bike is starting"
);
1.4 Conclusion
The Object-Oriented Programming paradigm is integral to the design and func-
tionality of the Java programming language. Its principles—encapsulation, in-
heritance, polymorphism, and abstraction—are woven into the very fabric of
Java, enabling developers to create modular, reusable, and maintainable code.
As Java continues to evolve, these OOP principles remain essential for build-
ing robust applications that can adapt to changing requirements in an efficient
manner.
1.5 Summary
This paper discusses the Object-Oriented Programming paradigm, highlight-
ing its core principles—encapsulation, inheritance, polymorphism, and abstrac-
tion—and its fundamental role in the Java programming language. By structur-
ing software through objects, Java enhances modularity, reusability, and main-
tainability, making it a powerful tool for developers in various domains.