2
Dec
Object-Oriented Programming is a very vital topic in java as well as any other high-level programming language. The main purpose of object-oriented programming is to increase the flexibility and maintainability of programs.
The core concepts are:
- Class
- Object
- Method
- Constructor
- Inheritance
- Encapsulation
- Polymorphism
- Abstraction
- Interface
1. Class:
A Class is a blueprint that states the properties and behavior of an object.
Example:
class Car{
String brand= "Toyota";
String model= "Premio";
public static void main(String[] args) {
Car myCar= new Car();
System.out.println(myCar.brand);
System.out.println(myCar.model);
}
}
2. Object:
An Object is an instance of a class. In the above example, myCar is an object. An object can be initiated by using new keyword before the class. An object can contain both properties and function.
Leave a Reply