OOPs concepts in Java

FullStackTips
5 min readFeb 5, 2023
Java OOPs concepts(image source: technicalround.com)

Java is an object-oriented programming (OOP) language that follows the key principles of OOP such as encapsulation, inheritance, and polymorphism. In this blog , we’ll take a look at four fundamental concepts and see how they are implemented in Java.

  1. Abstraction

Abstraction is a key OOP concept that involves hiding the implementation details and showing only the necessary information to the user. In Java, abstraction is achieved through the use of abstract classes and interfaces. An abstract class is a class that cannot be instantiated, but it can be extended by other classes to add new features and behaviors. An interface is a blueprint of a class that defines the methods that a class must implement.

abstract class Shape {
abstract void draw();
}

class Circle extends Shape {
void draw() {
System.out.println("Drawing a Circle");
}
}

class Rectangle extends Shape {
void draw() {
System.out.println("Drawing a Rectangle");
}
}

class Square extends Shape {
void draw() {
System.out.println("Drawing a Square");
}
}

class AbstractDemo {
public static void main(String[] args) {
Shape shape1 = new Circle();
Shape shape2 = new Rectangle();
Shape shape3 = new Square()

shape1.draw();
shape2.draw();
shape3.draw();

--

--

FullStackTips

I am full stack developer with over 15 years of experience in various programming languages. https://medium.com/@fullstacktips/membership