Oops Concept in Java

Intro­duc­tion to oops con­cepts in java -
In oops con­cepts in Java, OOPS Stands for “Object Ori­ent­ed Pro­gram­ming Sys­tem” it is a tech­nique, not tech­nol­o­gy. it means it doesn’t pro­vide any syn­tax or API.
oops, con­cepts in java pro­vide sug­ges­tions to devel­op objects in pro­gram­ming lan­guages.
oops, pro­gram­ming lan­guage intro­duced for rep­re­sent­ing a real-world busi­ness object by achiev­ing secu­ri­ty.
Anoth­er rea­son to invent oops is to achieve dynam­ic method dis­patch­ing.
which means from user pro­gram we should call an oper­a­tional method only once and it should
exe­cute from dif­fer­ent imple­men­ta­tion class­es auto­mat­i­cal­ly based on the class object we loaded.

Definition of OOPS

OOPS is a spec­i­fi­ca­tion or method­ol­o­gy or tech­nique that pro­vide a way of mod­u­lar­iz­ing a pro­gram by pro­vid­ing par­ti­tion mem­o­ry area for both data and log­ic that can be used as a tem­plate from cre­at­ing such modules(object) on demand.
Spec­i­fi­ca­tion means a doc­u­ment that con­tains rule and reg­u­la­tion for devel­op­ing a new appli­ca­tion.

OOPS, the spec­i­fi­ca­tion pro­vides a guide­line for devel­op­ing a new lan­guage for automat­ing busi­ness by cre­at­ing its object using a pro­gram.

oops concepts in java

Java supports the following oops concepts in java −

  1. Class­es
  2. Object
  3. Inher­i­tance
  4. Poly­mor­phism
  5. Encap­su­la­tion
  6. Abstrac­tion.
  1. Class — A class is a log­i­cal con­struct of the object that defines/​represents object, log­i­cal­ly with that object’s prop­er­ties and Behav­iors it is one of the impor­tant oops con­cepts in java.

A class can con­tain any of the fol­low­ing vari­able types.

Local variables −

Vari­ables defined inside meth­ods, con­struc­tors or blocks are called local vari­ables.

The vari­able will be declared and ini­tial­ized with­in the method and the vari­able will be destroyed when the method has com­plet­ed. Here test vari­able inside for­ward­ing method is a local vari­able.

Instance variables −

Instance vari­ables are vari­ables with­in a class but out­side any method. These vari­ables are ini­tial­ized when the class is instan­ti­at­ed.

Instance vari­ables can be accessed from inside any method, con­struc­tor or blocks of that par­tic­u­lar class. Here Gear, Col­or are instance vari­able.

Class variables −

Class vari­ables are vari­ables declared with­in a class, out­side any method, with the sta­t­ic key­word. Here Com­pa­ny is the Class vari­able.

  1. Object — It is encap­su­lat­ed form of a sta­t­ic and non-sta­t­ic method and vari­able.
  2. Inher­i­tance — In oops Inher­i­tance is the process of access­ing the prop­er­ties of the par­ent class in our sub­class is known as Inher­i­tance. The process of cre­at­ing a class to reuse exist­ed class mem­bers using our class name or object is called inher­i­tance.
  3. Poly­mor­phism — More than one method with the same name but dif­fer­ent sig­na­ture defined in the same class or with the same sig­na­ture defined in the dif­fer­ent class is called as polymorphism.Following oops con­cept demon­strate dif­fer­ent types of poly­mor­phism.
    • Method Over­load­ing
    • Method Over­rid­ing

    Method Overloading– 

    More than one method with the same name and with the same sig­na­ture defined in the same class is called as Method Over­load­ing.

    Method Overriding in oops-

    More than one method with same name and same sig­na­ture but defined in the dif­fer­ent class is called as Method Over­rid­ing.

  4. Encap­su­la­tion in oops– Encap­su­la­tion is the process of hid­ing the imple­men­ta­tion details from the out­side world and access­ing through a pub­licly exposed method that means set­ter or get­ter method.
  5. Abstrac­tion in java — Abstrac­tion is the process of hid­ing imple­men­ta­tion details and pro­vid­ing func­tion­al­i­ty to the user, in oth­er words, we can say show func­tion­al­i­ty and hide com­plex­i­ty. Abstrac­tion can be imple­ment­ed using abstract class and inter­face.