Directory Image
This website uses cookies to improve user experience. By using our website you consent to all cookies in accordance with our Privacy Policy.

Introduction to OOPs Concept

Author: Priyanka Abhivant
by Priyanka Abhivant
Posted: Apr 17, 2017

Introduction to OOPs Concept

There are two types of programming language, Procedure oriented programming language and Object oriented programming language. The language like C, Pascal, Fortran etc. are called as the Procedure oriented programming language. In the POPs languages when the programmer wants to write the program they divide the task into separate sub tasks each one expressed as a function. On the other hand the language like C# and Java etc. uses the Classes and objects in their programs and are called as Object oriented programming language. The OOPs concept have so many advantages over the POP language, when in POP language the code becomes longer it makes the programmer difficult to de bug and understand, the OOPs concept increase the reusability of code. Object Oriented Programming

Object oriented programming is a type of programming which uses the Classes and object to design the computer programs.

  • Features of OOPs

The main features of OOPs are:-

v Classes and Objects

v Encapsulation

v Abstraction

v Inheritance

v Polymorphism

v Class & Object :- Entire OOPs concept has been derived from these root word class and object without these the OOPs concept doesn’t exit.

In simple language the object is anything which exist in the world and can be distinguished from others. For e.g. table, chair etc. Every object have its own properties (variables) and action (method) which it perform. While we can say class is the model or blueprint for creating the objects or it is a collection of objects.

For ex.

Class Person{

//properties of the person

String name;

Int age;

// function of a person

Void talk()

{ }

Void eat()

{ }

}

v Abstraction :- As we have the lot of data in a class and the user does not need the entire data in this case we can hide the unnecessary data from the user and expose only that data that is of interest of the user. This is called as the Abstraction. For example, the car driver only wants to start the car but not want to do know how it start. The advantage of the abstraction is that every user will get the data of his own requirements and do not get confused with other data

For ex,

Class Bank{

Private int acco;

Private String name;

Private float balance;

Private float profit;

Private float loan;

Public void display_to_check(){

System.out.println("Acc. No."+ acco);

System.out.println("Name"+name);

}

Here we have used only the name and the account no and all the other fields are hidden.

v Encapsulation :- Encapsulation is the process in which we bind or wrap the data(variables) and code(methods) together. Class is an example of encapsulation which binds the variables and methods in it.Encapsulation protects the inner members(variables and methods) of the class from outside environment. It isolates the members form other class.

for ex.

Calss Employee{

Int id= 1001;

String name = "Lakshay";

Void displayDeatials(){

System.out.println("id = "+id);

System.out.println("name ="+name);

}

}

Calss Student{

Int id= 1002;

String name = "Akshay";

Void displayDeatials(){

System.out.println("id = "+id);

System.out.println("name ="+name);

}

}

Here we have seen that the variables are same but and not overriding each other as they are wrapped by different classes.

v Inheritance:- In simple words we can say "Inheritance" to acquire the features from others, when we create a new class and wants to use the feature of other class there we use the concept of inheritance. When we use the features of other class the original class is known as "Superclass" and the derived class is called the "Subclass".

For e.g.

Class A{

Protected int a;

Protected int b;

Public void method1()

{

}

}

Class B extends A {

Private int c;

Public void method2()

{

}

}

Here, we take class A with two variables a and b and a method1().Now all these features are needed in class B, we extend the class B from A so that we can use the features of class.

v POLYMORPHISM:- The word "Polymorphism " came from two Greek words "poly" meaning ‘many’ and "morphus" meaning ‘forms’. Thus polymorphism provides flexibility in writing programs in such a way that the programmer uses same method call to perform different operations depending on the requirement.

For e.g.

Class one{

Void calculate(int x){

System.out.println("Square value= "+ (x*x));

}

}

Class Two extends One{

Void calculate(int x){

System.out.println("cube value = "+(x*x*x));

}

}

Here we have seen that using one method we are performing two different task.

Rate this Article
Leave a Comment
Author Thumbnail
I Agree:
Comment 
Pictures
Author: Priyanka Abhivant

Priyanka Abhivant

Member since: Apr 04, 2017
Published articles: 1

Related Articles