{"id":17785,"date":"2023-03-07T13:15:00","date_gmt":"2023-03-07T07:45:00","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=17785"},"modified":"2026-03-11T18:51:05","modified_gmt":"2026-03-11T13:21:05","slug":"oops-concepts-in-java-4-basic-concepts","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/oops-concepts-in-java-4-basic-concepts\/","title":{"rendered":"OOPs Concepts in Java: 4 Basic Concepts Developers Must Know\u00a0"},"content":{"rendered":"\n<p>Ever wondered why Java is the backbone of so many enterprise applications, Android apps, and backend systems? A big part of the answer comes down to four foundational concepts: the four pillars of Object-Oriented Programming (OOPs).&nbsp;<\/p>\n\n\n\n<p>If you&#8217;re preparing for a tech interview or just starting your Java journey, understanding these pillars isn&#8217;t optional. It&#8217;s the entry ticket.<\/p>\n\n\n\n<p>In this article, you&#8217;ll learn exactly what OOPs is, what each of the four pillars means, how they work in real Java code, and why they matter in actual software development. No draggy stuff, just clear explanations, real examples, and code you can run yourself.<\/p>\n\n\n\n<p><strong>TL\/DR Summary:<\/strong><\/p>\n\n\n\n<p>Java&#8217;s OOPs is built on four pillars: <strong>Encapsulation<\/strong> hides your data and controls access, <strong>Inheritance<\/strong> lets classes reuse code from a parent class, <strong>Polymorphism<\/strong> allows one method to behave differently based on context, and <strong>Abstraction<\/strong> hides complexity and exposes only what&#8217;s necessary.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is OOPs (Object-Oriented Programming) in Java?<\/strong><\/h2>\n\n\n\n<p><strong>Direct Answer<\/strong>:<\/p>\n\n\n\n<p><strong>Object-Oriented Programming (OOPs) in <\/strong><a href=\"https:\/\/www.guvi.in\/blog\/java-for-beginners\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Java<\/strong><\/a> is a programming paradigm that organizes code around <strong>objects<\/strong> and <strong>classes<\/strong> rather than functions and logic alone. Java is one of the most widely used OOPs languages in the world, and its entire ecosystem, from Spring Boot to Android, is built on OOPs principles.<\/p>\n\n\n\n<p>OOPs makes your code more <strong>modular, reusable, secure, and easier to maintain<\/strong>. Instead of writing one giant block of instructions, you model your program around real-world entities (objects) that have properties (data) and behaviors (methods).<\/p>\n\n\n\n<div style=\"background-color: #099f4e; border: 3px solid #110053; border-radius: 12px; padding: 18px 22px; color: #FFFFFF; font-size: 18px; font-family: Montserrat, Helvetica, sans-serif; line-height: 1.6; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); max-width: 750px;\"><strong style=\"font-size: 22px; color: #FFFFFF;\">\ud83d\udca1 Did You Know?<\/strong> <br \/><br \/>Java isn&#8217;t considered 100% object-oriented; it still uses primitive data types like int, char, and boolean that aren&#8217;t objects. That&#8217;s a classic interview trap!<\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The 2 Building Blocks: Object and Class<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1200\" height=\"628\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/1-3.webp\" alt=\"The 2 Building Blocks: Object and Class\" class=\"wp-image-103652\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/1-3.webp 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/1-3-300x157.webp 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/1-3-768x402.webp 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/1-3-150x79.webp 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>Every OOPs program in Java revolves around two core building blocks (<a href=\"https:\/\/www.enjoyalgorithms.com\/blog\/classe-and-object-in-oops\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Class and Objects<\/a>) before the four pillars even come into play.<\/p>\n\n\n\n<p>A<strong> Class<\/strong> is a blueprint. It defines what properties and behaviors an object will have, but it doesn&#8217;t occupy memory on its own. Think of it like an architectural drawing for a house.<\/p>\n\n\n\n<p>An <strong>Object<\/strong> is a real instance of that class, the actual house built from the blueprint. It lives in memory and has actual values.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Class = Blueprint\n\nclass Car {\n\n&nbsp;&nbsp;&nbsp;&nbsp;String brand;\n\n&nbsp;&nbsp;&nbsp;&nbsp;int speed;\n\n&nbsp;&nbsp;&nbsp;&nbsp;void accelerate() {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(brand + \" is accelerating at \" + speed + \" km\/h\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}\n\n\/\/ Object = Real Instance\n\npublic class Main {\n\n&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String&#91;] args) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Car myCar = new Car(); &nbsp; &nbsp; &nbsp; \/\/ Creating an object\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myCar.brand = \"Toyota\";\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myCar.speed = 120;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myCar.accelerate();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ Output: Toyota is accelerating at 120 km\/h\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}<\/code><\/pre>\n\n\n\n<p>Simple enough, right? Now let&#8217;s get to the four pillars that make OOPs truly powerful.<\/p>\n\n\n\n<p>If you are planning on learning OOPs through a structured self-paced course, then consider enrolling in HCL GUVI\u2019s Certified <a href=\"https:\/\/www.guvi.in\/courses\/programming\/object-oriented-programming\/?utm_source=blog&amp;utm_medium=hyperlink+&amp;utm_campaign=oops-concepts-in-java-4-basic-concepts\" target=\"_blank\" rel=\"noreferrer noopener\">Object-Oriented Programming (OOPs) Course<\/a>, which is perfect for beginners looking to master OOPs fundamentals. It covers key concepts like classes, objects, inheritance, polymorphism, and design patterns.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The 4 OOPs Concepts in Java: Explained with Examples<\/strong><\/h2>\n\n\n\n<p>These four concepts are the heart of every <a href=\"https:\/\/www.guvi.in\/blog\/java-interview-questions-and-answers\/\" target=\"_blank\" rel=\"noreferrer noopener\">Java interview<\/a>, every <a href=\"https:\/\/www.guvi.in\/blog\/java-project-ideas-of-all-levels\/\" target=\"_blank\" rel=\"noreferrer noopener\">Java project<\/a>, and every Java framework you&#8217;ll ever work with. Let&#8217;s break each one down properly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Encapsulation: Protecting Your Data<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1200\" height=\"628\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/2-3.webp\" alt=\"Encapsulation: Protecting Your Data\" class=\"wp-image-103653\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/2-3.webp 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/2-3-300x157.webp 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/2-3-768x402.webp 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/2-3-150x79.webp 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>Encapsulation in OOPs is all about <strong>keeping your data safe from outside interference<\/strong>. You wrap your data (fields) and the methods that operate on that data inside a class, then restrict direct access using access modifiers. External code can only interact with your data through controlled methods, called <strong>getters and setters<\/strong>.<\/p>\n\n\n\n<p>Think of it like your bank account. You can check your balance and withdraw money through the ATM, but you can&#8217;t directly reach into the bank&#8217;s database and change your balance. The data is encapsulated.<\/p>\n\n\n\n<p>In Java, encapsulation is achieved by:<\/p>\n\n\n\n<ul>\n<li>Declaring class fields as private<\/li>\n\n\n\n<li>Providing public getter and setter methods to read and update those fields<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>class BankAccount {\n\n&nbsp;&nbsp;&nbsp;&nbsp;private double balance;&nbsp; \/\/ Hidden from outside world\n\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/ Controlled access through getter\n\n&nbsp;&nbsp;&nbsp;&nbsp;public double getBalance() {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return balance;\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/ Controlled update through setter\n\n&nbsp;&nbsp;&nbsp;&nbsp;public void deposit(double amount) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (amount &gt; 0) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;balance += amount;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}\n\npublic class Main {\n\n&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String&#91;] args) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BankAccount account = new BankAccount();\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;account.deposit(5000);\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(\"Balance: \" + account.getBalance()); \/\/ Balance: 5000.0\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ account.balance = 99999; \u2190 This would cause a compile error!\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}<\/code><\/pre>\n\n\n\n<p><strong>Why it matters:<\/strong> Encapsulation makes your code easier to maintain, debug, and test. You can change the internal implementation without breaking any code that uses the class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Inheritance: Don&#8217;t Repeat Yourself<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1200\" height=\"628\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/3-3.webp\" alt=\"Inheritance: Don&#039;t Repeat Yourself\" class=\"wp-image-103654\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/3-3.webp 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/3-3-300x157.webp 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/3-3-768x402.webp 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/3-3-150x79.webp 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>Inheritance allows one class (the <strong>child<\/strong> or subclass) to inherit the properties and methods of another class (the <strong>parent<\/strong> or superclass). Instead of rewriting the same code, you build on what already exists.<\/p>\n\n\n\n<p>This is the <strong>&#8220;IS-A&#8221; relationship<\/strong> in Java. A Dog IS-A Animal. A Tesla IS-A Car. The child gets everything the parent has, plus it can add its own unique features.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Parent class\n\nclass Animal {\n\n&nbsp;&nbsp;&nbsp;&nbsp;String name;\n\n&nbsp;&nbsp;&nbsp;&nbsp;void eat() {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(name + \" is eating.\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}\n\n\/\/ Child class inheriting from Animal\n\nclass Dog extends Animal {\n\n&nbsp;&nbsp;&nbsp;&nbsp;void bark() {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(name + \" says: Woof!\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}\n\npublic class Main {\n\n&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String&#91;] args) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dog dog = new Dog();\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dog.name = \"Bruno\";\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dog.eat(); &nbsp; \/\/ Inherited from Animal \u2192 Bruno is eating.\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dog.bark();&nbsp; \/\/ Dog's own method \u2192 Bruno says: Woof!\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}<\/code><\/pre>\n\n\n\n<p><strong>Types of Inheritance in Java:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Type<\/strong><\/td><td><strong>Description<\/strong><\/td><td><strong>Supported in Java?<\/strong><\/td><\/tr><tr><td>Single<\/td><td>One child inherits from one parent<\/td><td>Yes<\/td><\/tr><tr><td>Multilevel<\/td><td>Child \u2192 Parent \u2192 Grandparent chain<\/td><td>Yes<\/td><\/tr><tr><td>Hierarchical<\/td><td>Multiple children from one parent<\/td><td>Yes<\/td><\/tr><tr><td>Multiple<\/td><td>One child from multiple parents<\/td><td>Not via classes (use interfaces)<\/td><\/tr><tr><td>Hybrid<\/td><td>Combination of the above<\/td><td>Not directly (use interfaces)<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><strong>Types of Inheritance in Java<\/strong><\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Polymorphism: One Interface, Many Forms<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1200\" height=\"628\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/5-1.webp\" alt=\"Polymorphism\" class=\"wp-image-103655\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/5-1.webp 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/5-1-300x157.webp 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/5-1-768x402.webp 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/5-1-150x79.webp 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>The word &#8220;polymorphism&#8221; literally means <em>many forms<\/em>. In Java, it means you can use a single method name to perform different tasks depending on the context. This makes your code flexible, clean, and scalable.<\/p>\n\n\n\n<p>There are two types you need to know:<\/p>\n\n\n\n<p><strong>Compile-time Polymorphism (Method Overloading)<\/strong>: The method name is the same, but the parameters differ. Java decides which version to call at compile time.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Calculator {\n\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/ Same method name, different parameters\n\n&nbsp;&nbsp;&nbsp;&nbsp;int add(int a, int b) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return a + b;\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;double add(double a, double b) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return a + b;\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;int add(int a, int b, int c) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return a + b + c;\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}\n\npublic class Main {\n\n&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String&#91;] args) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Calculator calc = new Calculator();\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(calc.add(5, 3)); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ 8\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(calc.add(5.5, 3.2)); &nbsp; &nbsp; &nbsp; \/\/ 8.7\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(calc.add(1, 2, 3));&nbsp; &nbsp; &nbsp; &nbsp; \/\/ 6\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}<\/code><\/pre>\n\n\n\n<p><strong>Runtime Polymorphism (Method Overriding)<\/strong>: The child class provides a new version of a method already defined in the parent class. Java decides which version to call at runtime.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Shape {\n\n&nbsp;&nbsp;&nbsp;&nbsp;void draw() {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(\"Drawing a shape\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}\n\nclass Circle extends Shape {\n\n&nbsp;&nbsp;&nbsp;&nbsp;@Override\n\n&nbsp;&nbsp;&nbsp;&nbsp;void draw() {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(\"Drawing a circle\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}\n\nclass Rectangle extends Shape {\n\n&nbsp;&nbsp;&nbsp;&nbsp;@Override\n\n&nbsp;&nbsp;&nbsp;&nbsp;void draw() {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(\"Drawing a rectangle\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}\n\npublic class Main {\n\n&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String&#91;] args) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Shape s1 = new Circle();\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Shape s2 = new Rectangle();\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s1.draw();&nbsp; \/\/ Drawing a circle\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s2.draw();&nbsp; \/\/ Drawing a rectangle\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}<\/code><\/pre>\n\n\n\n<p><strong>Overloading vs Overriding: Quick Comparison:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Feature<\/strong><\/td><td><strong>Method Overloading<\/strong><\/td><td><strong>Method Overriding<\/strong><\/td><\/tr><tr><td>Where<\/td><td>Same class<\/td><td>Parent &amp; Child class<\/td><\/tr><tr><td>Parameters<\/td><td>Must differ<\/td><td>Must be same<\/td><\/tr><tr><td>Return type<\/td><td>Can differ<\/td><td>Must be same (or covariant)<\/td><\/tr><tr><td>Resolved at<\/td><td>Compile time<\/td><td>Runtime<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><strong>Overloading vs Overriding<\/strong><\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Abstraction: Show What Matters, Hide What Doesn&#8217;t<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1200\" height=\"628\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/6.webp\" alt=\"Abstraction\" class=\"wp-image-103656\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/6.webp 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/6-300x157.webp 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/6-768x402.webp 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/03\/6-150x79.webp 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>Abstraction is about <strong>simplifying complexity<\/strong>. You expose only the essential features of an object and hide the internal implementation details. Users of your class don&#8217;t need to know <em>how<\/em> something works, just <em>that<\/em> it works.<\/p>\n\n\n\n<p>You use an ATM every day without knowing the internal banking logic, right? That&#8217;s abstraction in real life.<\/p>\n\n\n\n<p>In Java, abstraction is achieved through two mechanisms:<\/p>\n\n\n\n<ul>\n<li><strong>Abstract Classes<\/strong>: Can have both abstract (unimplemented) and concrete (implemented) methods<\/li>\n\n\n\n<li><strong>Interfaces<\/strong>: Fully abstract by default (all methods are abstract unless marked default or static)<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Abstract class \u2014 defines the \"what\", not the \"how\"\n\nabstract class Vehicle {\n\n&nbsp;&nbsp;&nbsp;&nbsp;String brand;\n\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/ Abstract method \u2014 no implementation here\n\n&nbsp;&nbsp;&nbsp;&nbsp;abstract void fuelType();\n\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/ Concrete method \u2014 shared implementation\n\n&nbsp;&nbsp;&nbsp;&nbsp;void startEngine() {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(brand + \"'s engine started.\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}\n\nclass ElectricCar extends Vehicle {\n\n&nbsp;&nbsp;&nbsp;&nbsp;@Override\n\n&nbsp;&nbsp;&nbsp;&nbsp;void fuelType() {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(brand + \" runs on electricity.\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}\n\nclass PetrolCar extends Vehicle {\n\n&nbsp;&nbsp;&nbsp;&nbsp;@Override\n\n&nbsp;&nbsp;&nbsp;&nbsp;void fuelType() {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(brand + \" runs on petrol.\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}\n\npublic class Main {\n\n&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String&#91;] args) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Vehicle v1 = new ElectricCar();\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;v1.brand = \"Tesla\";\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;v1.startEngine(); &nbsp; \/\/ Tesla's engine started.\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;v1.fuelType();&nbsp; &nbsp; &nbsp; \/\/ Tesla runs on electricity.\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}<\/code><\/pre>\n\n\n\n<p><strong>Abstract Class vs Interface: Know the Difference:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Feature<\/strong><\/td><td><strong>Abstract Class<\/strong><\/td><td><strong>Interface<\/strong><\/td><\/tr><tr><td>Methods<\/td><td>Abstract + Concrete<\/td><td>Abstract (+ default\/static)<\/td><\/tr><tr><td>Variables<\/td><td>Any type<\/td><td>public static final only<\/td><\/tr><tr><td>Inheritance<\/td><td>extends (single)<\/td><td>implements (multiple)<\/td><\/tr><tr><td>Constructor<\/td><td>Can have<\/td><td>Cannot have<\/td><\/tr><tr><td>Use when<\/td><td>Shared base behavior<\/td><td>Define a contract\/capability<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><strong>Abstract Class vs Interface<\/strong><\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Abstraction vs Encapsulation: The Confusion Cleared<\/strong><\/h2>\n\n\n\n<p>This is one of the most commonly asked interview questions, and honestly, it trips up a lot of people. Here&#8217;s the clearest way to think about it:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><\/td><td><strong>Abstraction<\/strong><\/td><td><strong>Encapsulation<\/strong><\/td><\/tr><tr><td><strong>Focus<\/strong><\/td><td>Hiding <em>complexity<\/em><\/td><td>Hiding <em>data<\/em><\/td><\/tr><tr><td><strong>Goal<\/strong><\/td><td>Show only what&#8217;s relevant<\/td><td>Protect internal state<\/td><\/tr><tr><td><strong>Achieved via<\/strong><\/td><td>Abstract classes, Interfaces<\/td><td>Private fields, Getters\/Setters<\/td><\/tr><tr><td><strong>Real-world<\/strong><\/td><td>ATM interface hides banking logic<\/td><td>ATM PIN hidden from the screen<\/td><\/tr><tr><td><strong>Level<\/strong><\/td><td>Design level<\/td><td>Implementation level<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><strong>Abstraction vs Encapsulation<\/strong><\/figcaption><\/figure>\n\n\n\n<p><strong>One-liner to remember:<\/strong> Abstraction is about <em>what<\/em> an object does. Encapsulation is about <em>how<\/em> it protects what it has.<\/p>\n\n\n\n<p>If you want to take this further and build full Java-based applications from the ground up with mentor guidance, then check out HCL GUVI&#8217;s Certified <a href=\"https:\/\/www.guvi.in\/zen-class\/java-full-stack-development-course\/?utm_source=blog&amp;utm_medium=hyperlink+&amp;utm_campaign=oops-concepts-in-java-4-basic-concepts\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Java Full Stack Developer Course<\/strong><\/a>. You&#8217;ll go from OOPs fundamentals all the way to deploying real-world projects and in the end you will be getting an industry-grade certification!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>In conclusion, OOPs isn&#8217;t just a theoretical concept you mug up for interviews and forget. It&#8217;s the <strong>practical architecture<\/strong> of every Java application built at scale. You now understand what Encapsulation, Inheritance, Polymorphism, and Abstraction really mean: not just in definition, but in actual working code.<\/p>\n\n\n\n<p>The best way to truly lock these in? Build something. Take any small real-world scenario, a library system, a vehicle management app, or a simple banking program, and implement it using all four OOPs pillars. You&#8217;ll be surprised how quickly the concepts click.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>FAQs<\/strong><\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1772175372995\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>1. What are the 4 pillars of OOPs in Java?<\/strong>\u00a0<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>The four pillars are Encapsulation (data hiding through access modifiers), Inheritance (reusing code via parent-child class relationships), Polymorphism (one method, multiple behaviors through overloading and overriding), and Abstraction (hiding complexity through abstract classes and interfaces).<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1772175376089\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>2. What is the difference between abstraction and encapsulation in Java?<\/strong>\u00a0<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Abstraction hides complexity at the design level using abstract classes and interfaces. Encapsulation hides data at the implementation level using private fields and getter\/setter methods. Abstraction is about <em>what<\/em> an object does; encapsulation is about <em>how<\/em> it protects its data.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1772175381487\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>3. What are the types of polymorphism in Java?<\/strong>\u00a0<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Java supports two types: compile-time polymorphism (method overloading, same method name, different parameters) and runtime polymorphism (method overriding, child class redefines a parent class method).<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1772175385786\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>4. What are the types of inheritance in Java?<\/strong>\u00a0<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Java supports single, multilevel, and hierarchical inheritance through classes. Multiple and hybrid inheritance are achieved through interfaces, since Java doesn&#8217;t allow a class to extend multiple classes.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1772175393653\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>5. Is Java 100% object-oriented?<\/strong>\u00a0<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>No. Java uses primitive data types (int, char, boolean, float, etc.) that are not objects. This makes Java not purely object-oriented. However, Java provides wrapper classes (like Integer, Character) to treat primitives as objects when needed.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Ever wondered why Java is the backbone of so many enterprise applications, Android apps, and backend systems? A big part of the answer comes down to four foundational concepts: the four pillars of Object-Oriented Programming (OOPs).&nbsp; If you&#8217;re preparing for a tech interview or just starting your Java journey, understanding these pillars isn&#8217;t optional. It&#8217;s [&hellip;]<\/p>\n","protected":false},"author":22,"featured_media":103650,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37,294,720],"tags":[],"views":"16476","authorinfo":{"name":"Lukesh S","url":"https:\/\/www.guvi.in\/blog\/author\/lukesh\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/03\/4-Basic-Concepts-Developers-Must-Know-300x116.webp","jetpack_featured_media_url":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/03\/4-Basic-Concepts-Developers-Must-Know.webp","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/17785"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=17785"}],"version-history":[{"count":39,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/17785\/revisions"}],"predecessor-version":[{"id":103657,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/17785\/revisions\/103657"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/103650"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=17785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=17785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=17785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}