Object-Oriented Programming Concepts: OOP, Class & Object
In this lecture i will talk about the basic Object-Oriented Programming Concepts such as OOP, Class & Object. By following the lecture you will get very clear idea about the OOP, Class & Object.
Table Of Contents
What is Object-oriented Programming?
Object-oriented programming is a methodology which helps us to create or design a program using classes and objects in a structured way. OOP is also connected with the concepts such as class, object, inheritance, encapsulation etc.
Advantage of OOP
– OOP improves program quality
– It is fast and easy to maintain
– Reduce development time
– Reusable code
What is Class?
A class is blueprint or set of instructions from which objects are created. A class contains properties and methods it determines how an object will behave and what kind of data the object will contain.
How to define Class in Java?
class ClassName{
// properties
// methods
}
Example
class Animal {
private String name;
int age;
String color;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
What is Object?
An Object is an example of a class. It determines the behavior of a class. When an object is created, memory is allocated.
Example
Animal cat = new Animal();