0% found this document useful (0 votes)
3 views

Java_OOPs_Concepts_With_Examples

The document outlines key Java OOP concepts including classes and objects, inheritance, polymorphism, abstraction, and encapsulation. Each concept is briefly defined and illustrated with code examples. These principles are fundamental for object-oriented programming in Java.

Uploaded by

ADITYA VERMA
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)
3 views

Java_OOPs_Concepts_With_Examples

The document outlines key Java OOP concepts including classes and objects, inheritance, polymorphism, abstraction, and encapsulation. Each concept is briefly defined and illustrated with code examples. These principles are fundamental for object-oriented programming in Java.

Uploaded by

ADITYA VERMA
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
You are on page 1/ 2

Java OOPs Concepts with Examples

1. Class and Object

A class is a blueprint for objects. An object is an instance of a class.

Example:

class Car {

String color;

void drive() {

System.out.println("Car is driving");

2. Inheritance

Inheritance allows one class to acquire properties of another.

Example:

class Animal {

void eat() { System.out.println("Eating..."); }

class Dog extends Animal {

void bark() { System.out.println("Barking..."); }

3. Polymorphism

Polymorphism means many forms. Method overloading and overriding are examples.

Example:

class Demo {

void show(int a) {}

void show(String b) {}
}

4. Abstraction

Abstraction hides complexity by showing only essential details.

Example:

abstract class Shape {

abstract void draw();

5. Encapsulation

Encapsulation is wrapping data and code into a single unit.

Example:

class Person {

private String name;

public String getName() { return name; }

public void setName(String n) { name = n; }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy