0% found this document useful (0 votes)
2 views2 pages

Java OOPs Interview Notes

Uploaded by

Munasa Pavani
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Java OOPs Interview Notes

Uploaded by

Munasa Pavani
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java OOP Concepts — Interview Notes

Java OOP Concepts — Detailed Notes for Interview Preparation


1. CLASS & OBJECT Definition: A class is a blueprint for creating objects. It defines data
(variables) and behavior (methods). An object is an instance of a class that represents real-world
entities.
Syntax: class ClassName { int variable; void display() { [Link]("Hello!"); } }
Example: class Student { int id; String name; void display() { [Link](id + " " + name); } }
Memory Allocation: Objects are stored in Heap memory, references in Stack memory.
------------------------------------------------------------
2. ABSTRACTION Definition: Abstraction means hiding internal details and showing only essential
features. Achieved using abstract classes and interfaces.
Abstract Class Example: abstract class Animal { abstract void sound(); void eat() {
[Link]("Animals eat"); } } class Dog extends Animal { void sound() {
[Link]("Dog barks"); } }
Interface Example: interface Vehicle { void start(); default void fuelType() {
[Link]("Petrol"); } static void maintenance() { [Link]("Service yearly"); } }
class Car implements Vehicle { public void start() { [Link]("Car starts"); } }
------------------------------------------------------------
3. ENCAPSULATION Definition: Encapsulation is binding data and methods into a single unit
(class) and hiding data using private access modifiers.
Example: class Student { private int rollNo; private String name;
public int getRollNo() { return rollNo; } public void setRollNo(int rollNo) { [Link] = rollNo; } public
String getName() { return name; } public void setName(String name) { [Link] = name; } }
Advantages: - Data hiding - Validation control - Security and maintainability
------------------------------------------------------------
4. INHERITANCE Definition: Inheritance allows one class to acquire properties and methods of
another class using 'extends'.
Example: class Animal { void eat() { [Link]("Eating"); } } class Dog extends Animal {
void bark() { [Link]("Barking"); } }
super keyword: Used to call parent class methods or constructors.
Constructor Chaining: Occurs from parent to child using super().
Types: - Single - Multilevel - Hierarchical (Multiple inheritance supported through interfaces)
------------------------------------------------------------
5. POLYMORPHISM Definition: Polymorphism means many forms — same method performs
differently based on context.
Types: 1. Compile-time (Method Overloading) 2. Runtime (Method Overriding)
Example (Overloading): class Calculator { int add(int a, int b) { return a + b; } double add(double a,
double b) { return a + b; } }
Example (Overriding): class Animal { void sound() { [Link]("Animal sound"); } } class
Dog extends Animal { void sound() { [Link]("Dog barks"); } }
Dynamic Dispatch: Animal a = new Dog(); [Link](); // Dog’s method executes
------------------------------------------------------------
Summary Table: | Concept | Key Idea | |----------|-----------| | Class/Object | Blueprint & instance | |
Abstraction | Hiding details, showing essentials | | Encapsulation | Data hiding using private fields | |
Inheritance | Reusing code using extends | | Polymorphism | Same action, different behavior |

You might also like