Java Tutorial: 5(OOPs Concepts in JAVA)


OOPs i.e Object Oriented Programming is an approach that uses Object which makes it more structured. It binds the data and functions that operate on that particular data and also providing partitioned memory for both. Below are the different concepts of OOPs used in JAVA programming:

  • Abstraction: It is the concept of hiding the internal details and describing things in simple terms. For example, a method that adds two integers. The internal processing of the method is hidden from the outer world. There are many ways to achieve abstraction in object-oriented programmings, such as encapsulation and inheritance.
  • Encapsulation: Encapsulation lets us re-use functionality without jeopardizing security. It’s a powerful OOP concept in Java because it helps us save a lot of time. For example, we may create a piece of code that calls specific data from a database. It may be useful to reuse that code with other databases or processes. Encapsulation lets us do that while keeping our original data private. It also lets us alter our original code without breaking it for others who have adopted it in the meantime.
  • Polymorphism: It is the concept in object-oriented programming, the child class can inherit its parent class methods, also it can add unique features to that behavior. Polymorphism can be achieved by method overloading or overriding.
          Method Overloading:
          public class Overloading {
          public int add( int a,int b) {
              int rts=a+b;
              return rts;
           }
          public int add( int a,int b,int c) {
               int rts=a+b+c;
               return rts;
           }
           public static void main(String[] args) {
                Overloading overload=new Overloading();
                System.out.println(overload.add(9,10,11));
               System.out.println(overload.add(9,510));
            }
           }          
  • Inheritance: It is the process by which objects of one class acquire some properties of objects of another class. Inheritance supports the concept of hierarchical classification. For Example, a bird Robin is part of the class, not a mammal, which is again a part of the class Animal. The principle behind this division is that each subclass shares common characteristics from the class from its parent class. 
  • Association: It is the OOPS concept to define the relationship between objects. The association defines the multiplicity between objects. For example Teacher and Student objects. There is a one-to-many relationship between a teacher and students. Similarly, a student can have a one-to-many relationship with teacher objects. However, both student and teacher objects are independent of each other.

Comments