KEMBAR78
? Page 4 | PDF
0% found this document useful (0 votes)
11 views1 page

? Page 4

The document outlines key concepts of Object-Oriented Programming (OOP) in Java, including classes, objects, encapsulation, inheritance, polymorphism, and abstraction. It provides examples of creating a class and object, using a constructor, and demonstrating inheritance with a Dog class extending an Animal class. These concepts are fundamental for structuring and organizing code in Java.

Uploaded by

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

? Page 4

The document outlines key concepts of Object-Oriented Programming (OOP) in Java, including classes, objects, encapsulation, inheritance, polymorphism, and abstraction. It provides examples of creating a class and object, using a constructor, and demonstrating inheritance with a Dog class extending an Animal class. These concepts are fundamental for structuring and organizing code in Java.

Uploaded by

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

📄 Page 4: Object-Oriented Programming in Java

OOP Concepts

 Class: Blueprint for objects


 Object: Instance of a class
 Encapsulation: Data hiding using private access
 Inheritance: Reuse of code between classes
 Polymorphism: Many forms (method overloading/overriding)
 Abstraction: Hiding complexity

Creating a Class and Object


java
CopyEdit
class Car {
String color = "Red";
void drive() {
System.out.println("Car is driving");
}
}
public class Main {
public static void main(String[] args) {
Car myCar = new Car();
myCar.drive();
}
}

Constructor
java
CopyEdit
class Student {
Student() {
System.out.println("Constructor called");
}
}

Inheritance Example
java
CopyEdit
class Animal {
void sound() { System.out.println("Animal sound"); }
}
class Dog extends Animal {
void bark() { System.out.println("Dog barks"); }
}

You might also like