Basics Features of Object Oriented Programing Language. - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript Basics Features of Object Oriented Programing Language. - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Saturday, June 17, 2017

Basics Features of Object Oriented Programing Language.


Basics Features of Object Oriented Programing Language.



Features of OOP : -
1.Class
2.Object
3.Inheritance
4.Polymorphism
5.Data Hiding And Encapsuation

Class : - Class is a group of object of same of same type .Once a class has declared we can create multiple numbers of their objects. E.g potato, onion, Cabbage are the object of class vegetables.

Example of Class in JAVA: -

Class Hello //Class hello
{

}



Object : - Objects are collection of entities .Object takes space in memory . Objects are instances of class. When program is executed the object the object interacts by sending message to another . Each object contain data and code to mainpulate the data.

Example of Class and Objects : -

Class Hello //Class hello
{
void run () //Member Function
{
System.out.print(“Hello World”);
}
}
class demo
{
public static void main (String args[])
{
Hello h=new Hello(); // Creating Object of class hello
h.run(); //Calling Method of class hello
}
}

Inheritance : - Inheritance is an Approach through in which object of one class can acquired the property of parents class. Inheritance is used for resuablity of codes.

Example of Inheritance
Class employee
{
int salary=1000;
}
//Extend is used to access the feature and property of parent class

Class developer extends employee
{
int bonus=500;
public static void main(String args[])
{
developer d=new developer();
System.out.println(“Salary is : ”+d.salary);
System.out.println(“Bonus is : ”+d.bonus);
}
}

Polymorphism : - the word polymorphism means many form any operation may exhibite different behaviour in different instance . The behaviour depend on what type of operation we used.
Example :- Function Overloading,Operator Overloading.

Example of Polymorphism

class adding
{
int add(int a,int b) //method one
{
return a+b;
}
// method two same name but differen parameter
int add(int a,int b,int c)
{
return a+b+c;
}
}
class demo
{
public static void main(String args[])
{
adding abc=new adding();
System.out.println(“Sum of 10 , 20 , 30 is : ”+abc.add(10,20,30));
System.out.println(“Sum of 10 , 20 is : ”+abc.add(10,20));
}
}

Data hiding and Encapsulation : - Since wrapping up of data member and menber in a single class is known as encapsulation. Through in which data as are not access by the outside world only member function can access the data this is data hiding. And Also when we hide the complexity of program are known as abstraction . And only essential feature can access. Like when we sending sms we dont what its internal processing we only give inputs.

Example of Encapsulation

class hello
{
int a;
void geta()
{
return a;
}
void seta(String n)
{
this.a=n;
}
}
//hiding the above class and then we only calling the method dont know about the internal processing.
class calling
{
public static void main(String args[])
{
hello h=new hello();
h.seta(“Charles”);
System.out.print(“Name is ”+h.geta());
}
}

No comments:

Post a Comment

Post Top Ad