PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Java · Theory

OOPs Concepts in Java

← All stacks

Theory

26/270

OOPs Concepts in Java

OOP means you build software from objects, not from 200 loose variables. An object keeps data and actions together. A BankAccount has balance and also deposit(). A Student has name and also study(). That is the whole idea. A class is the blueprint on paper. new makes one real object from that blueprint.

Four pillars — don’t only chant the names. Encapsulation: keep balance private; only deposit() can change it. Inheritance: Dog extends Animal and reuses eat(). Polymorphism: speak() is bark for Dog and meow for Cat. Abstraction: startEngine() hides the messy fuel work. One everyday word each, or the interviewer will stop you.

Let’s take BankAccount on the board. Class has private double balance. Method deposit(100) adds only if amt > 0. getBalance() returns the number. Outside code cannot write acc.balance = -99. That one example is encapsulation + class + object together. Draw it once in your notebook.

Companies use OOP because a big project is easier to grow when each piece has a clear job. You can test BankAccount without opening the whole website. You can reuse Student in two screens. If everything is public fields in main, one change breaks ten places.

Learn class and object first, then encapsulation, then inheritance, then polymorphism, then abstract class vs interface. If you skip to interface on day one, you will only memorise implements. Walk the order like a class timetable.

Diagram
Class: BankAccount   (blueprint)
           │ new
           ▼
  Object: acc1          (real account)
     balance (private)
     deposit() / getBalance()
Exam tip

Four pillars × one line × one example word. Don’t only recite names.

Example

class BankAccount {
  private int balance;
  BankAccount(int start) { this.balance = start; }
  void deposit(int amt) { if (amt > 0) balance += amt; }
  int getBalance() { return balance; }
}
public class Main {
  public static void main(String[] args) {
    BankAccount a = new BankAccount(100);
    a.deposit(50);
    System.out.println(a.getBalance());
  }
}

OOPs Concepts in Java — output: 150. Start 100 + deposit 50. balance is private — that is encapsulation, one OOP pillar.

Short notes

  • DefOOP = build programs from objects. Object = data + actions together.
  • RuleClass is blueprint. Object is made with new.
  • Remember4 pillars — encapsulation, inheritance, polymorphism, abstraction.
  • Useprivate balance + deposit; Dog extends Animal; speak() differs; startEngine() hides details.

Questions

1

What is OOP?

2

Class vs object?

3

Name the four pillars.

4

Give one example for encapsulation.

5

Give one example for inheritance.

Previous← Java ProgramsNextJava Naming Convention →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.