Object-Oriented Programming in Java
Hi Readers; Hope you all are fine.
In this article, I’m going to describe OOP concepts in Java.
Past time software developers use procedural programming language. Cost overruns, delays, not meeting user expectations are some drawbacks of procedural programming language. Since of this cause Object-Oriented Concepts are introduced.
Objects and classes are the core concepts in OOP. Firstly we‘ll talk about what is a class?
Class
The collection of objects is known as class. A class also can be defined as a blueprint.
public class Demo{ //defintion of class
public static void main(String args []) { // main method
}
}
Object
The object is a real-world entity such as a person, chair, table, etc. object that can be logical or physical. State and behavior are characteristics of an object. As an example person is an object who has a state like a name, age, school as well as behaviors like a person can eat, drink, and walk.
public class Demo{ //defintion of class
public static void main(String args[]) { // main method
Person p1=new Person(); // define a p1 object
Person p2= new Person(); // define a p2 object
}
}
class Person{ // definition of class
}
We’ll see an example for whole things that we are learned.
public class Demo{ //defintion of class
public static void main(String args []){//main method
Person p1=new Person(); // define a p1 object
p1.eat(); // method callling
System.out.println(p1.name);
System.out.println(p1.age);
}
}
class Person{ // definition of class
int age = 50; // state of person object
String name = "Sunil"; // states of person object
public void eat(){ //behaviour of person object
System.out.println("Person is speaking");
}
}
the output of the above source code...
Person is speaking
Sunil
50
Hope you will learn the basic concepts of java. Stay tuned for the next article about object-oriented concepts in Java.
Thank You!!