KEMBAR78
OOP Concepts Java NetBeans | PDF | Object Oriented Programming | Method (Computer Programming)
0% found this document useful (0 votes)
16 views8 pages

OOP Concepts Java NetBeans

The document provides an overview of Object-Oriented Programming (OOP) concepts in Java, including classes, objects, encapsulation, inheritance, polymorphism, and abstraction, with examples using Java NetBeans. It highlights the benefits of OOP such as code reusability, modularity, scalability, maintainability, and better collaboration. Each concept is illustrated with code snippets to demonstrate practical implementation.

Uploaded by

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

OOP Concepts Java NetBeans

The document provides an overview of Object-Oriented Programming (OOP) concepts in Java, including classes, objects, encapsulation, inheritance, polymorphism, and abstraction, with examples using Java NetBeans. It highlights the benefits of OOP such as code reusability, modularity, scalability, maintainability, and better collaboration. Each concept is illustrated with code snippets to demonstrate practical implementation.

Uploaded by

Rainanz Socuano
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Object-Oriented Programming

Concepts in Java
With Examples Using Java NetBeans
Introduction to OOP
• Object-Oriented Programming (OOP) is a
paradigm based on the concept of 'objects'. In
Java, OOP helps in writing modular, reusable,
and maintainable code.
Classes and Objects
• A class is a blueprint for objects. Objects are
instances of a class.
public class Car {
String model;
String color;

void drive() {
System.out.println(model + " is driving.");
}

public static void main(String[] args) {


Car car1 = new Car();
car1.model = "Toyota";
car1.color = "Red";
car1.drive();
}
}
Encapsulation
• Encapsulation is achieved by making variables
private and providing public getters and
setters.
public class Student {
private String name; // private variable

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public static void main(String[] args) {


Student s = new Student();
s.setName("Ace");
System.out.println("Student name: " + s.getName());
}
}
Inheritance
• Inheritance allows one class to inherit fields
and methods from another class using
'extends'.
class Animal {
void sound() {
System.out.println("Animal makes a sound");
}
}

class Dog extends Animal {


void sound() {
System.out.println("Dog barks");
}

public static void main(String[] args) {


Dog d = new Dog();
d.sound();
}
}
Polymorphism
• Polymorphism allows the same method to
take many forms (overriding and overloading).
class Calculator {
int add(int a, int b) {
return a + b;
}
double add(double a, double b) {
return a + b;
}
}

class Main {
public static void main(String[] args) {
Calculator c = new Calculator();
System.out.println(c.add(2, 3));
System.out.println(c.add(2.5, 3.5));
}
}
Abstraction
• Abstraction is hiding implementation details
and showing only functionality using abstract
classes or interfaces.
abstract class Shape {
abstract void draw();
}

class Circle extends Shape {


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

public class Main {


public static void main(String[] args) {
Shape s = new Circle();
s.draw();
}
}
Benefits of OOP in Java
• • Code Reusability
• • Modularity
• • Scalability
• • Maintainability
• • Better collaboration

You might also like