What is OOP Language?
Object:
OOP stand for Object Oriented Programming. Before diving into explaining the term OOP we little explain the word Object. The term object is already familiar to you. Anything which exist around us is called object like a computer,laptop,speaker,person being, keyboard,van and bicycle etc are called object. Every object posses two main things.
1. Attributes or Properties. For example a person being has properties like this
1 . Name
2. Height
3. Complexion
4. Weight
5. Date of Birth
6. Place of Birth
7. Country of Birth
All of above are the properties of an human being. All objects on earth posses some of the properties or attributes.
2. Behaviour or Actions or activities
All objects on earth shows some behaviour or actions to perform some task.
For an human can run, walk, eat, sleep etc. All these things shows that an object in real world performs some action. These actions are called its Behaviour or actions or methods etc.
Moreover every object exist independent of the other objects and can interact with each other in specific way create some thing new or to perform some greater action.
Now the concept of Object is clear to you that what is an object and what it has?
Object Oriented Programming
Now we move to the term OOP. As we already know that JAVA is a object oriented language. Any language which relates its program with the real world objects is called OOP language and this practice is called Object Oriented Programming. In short words an OOP models its program in terms of real world objects.Object-oriented programming is an approach to building computer programs that mimics how objects are assembled in the physical world.By using this style of development, you can create programs that are more reusable,reliable, and understandable.
Organization of OOP
In JAVA an Object Oriented Program is constructed or organized in terms of Classes.What is Class ?
A class is blueprint or container or prescription on the basis of which objects are created.
A class in JAVA is simply created by using the keyword Class followed by the name of class and the braces in which the body of class exists.
For example
Class person
{
//List of Fields
//Method Definitions
}
Here Class is keyword, human is the name of class and braces {...} forms the body of the class.
In essence, a class definition is very simple. There are just two kinds of things that you can include in a class definition:
❑ Fields—These are variables that store data items that typically differentiate one object of the
class from another. They are also referred to as data members of a class.
❑ Methods—These define the operations you can perform for the class—so they determine what
you can do to, or with, objects of the class. Methods typically operate on the fields—the variables
of the class.
The fields in a class definition can be of any of the primitive types, or they can be references to objects of any class type, including the one that you are defining.
The methods in a class definition are named, self-contained blocks of code that typically operate on the fields that appear in the class definition.
A class is a template used to create an object. Every object created from the same class has
similar features.Classes embody all features of a particular set of objects. And all objects created from a class are similar except that these are differentiated from each other on the basis of their properties. For examples are all person are similar but posses different properties.
Following Class Dog describes all concepts of Class, fields and Methods.
How class is defined?
How Class variables also called Fields are defined?
How Methods are Defined?
How Objects are created?
How Fields and Methods are used and accessed?
public class Dog
{
// Instance Variables
public String name; String breed; int age; String color;
// Constructor Declaration of Class
public Dog(String name, String breed,
int age, String color)
{
this.name = name;
this.breed = breed;
this.age = age;
this.color = color;
}
//Method
public String barking(){
return("Tuffy is Barking now..Booow...Booow...Booow");
}
public static void main(String[] args)
{
Dog tuffy = new Dog("tuffy","papillon", 5, "white");
System.out.println(tuffy.name);
System.out.println(tuffy.breed);
System.out.println(tuffy.age);
System.out.println(tuffy.color);
System.out.println(tuffy.barking());
}
}
Now after reviving our previous concept of OOP we move on the further OOP terms like
Inheritance
polymorphism
overloading,overriding etc