Encapsulation is nothing about wrapping or binding up of data and method into a single unit.This reduces the complexity of the program with the help of method.It is one of the object oriented concept.
It contain the method and the method acts as the capsule that perform the operation whenever needed. The following will describe about the encapsulation.
Example:
public class Tony{
void a()
{
system.out.println(hai);
}
int n(int e)
{
system.out.println(e);
return 0;
}
public static void main (String args[])
{
Tony obj=new Tony();
obj.a();
obj.n(5);
}
}
The above example contain the methods, The methods contain the statement and data here we are binding statements and data into a single unit and sends to the main method so this is called the ENCAPSULATION.
It contain the method and the method acts as the capsule that perform the operation whenever needed. The following will describe about the encapsulation.
Example:
public class Tony{
void a()
{
system.out.println(hai);
}
int n(int e)
{
system.out.println(e);
return 0;
}
public static void main (String args[])
{
Tony obj=new Tony();
obj.a();
obj.n(5);
}
}
The above example contain the methods, The methods contain the statement and data here we are binding statements and data into a single unit and sends to the main method so this is called the ENCAPSULATION.
ABSTRACTION:
Abstraction is the process of hiding the implementation details and showing only the functionality details for example while programming you are showing only the output to the user not your but the abstract keyword.
Abstract is like an index of the page, if the index is refereed then it is easy to find the respective page. while the abstract class contain the name car, then the following extended class contain the name car, then the following extended class contain respective car name like Audi , Benz, ford etc..
All the class contain the same common methods like overseeing , break and steering so these method are placed in the abstract so while seeing abstract itself it is easy to find the extended method contain the following methods. Abstract method contain the abstract keyword. The abstract method cannot define in the abstract class.
Syntax:
abstract void a();
Abstract class
Abstract class contain the abstract keyword
Example :
abstract class cat
{
abstract void drive();
}
class audi extends car
{
@override
void drive()
{
//TO-DO auto-generated method stub
system.out.println(driving Audi);
}
}
class Benz extends car
{
@override
void drive()
{
//Todd auto-generated method stub
system.out.println(Benz);
}
}
public class Abstractclass
{
public static void main (String args[])
{
car c1=new Audi();
cat c2=new Benz();
c1.drive();
c2.drive();
}
}
In java abstract we cant create the object , It is possible to refer the abstract class to another class. By default abstract contain the abstract keyword . Abstract method must be extended to some class and by default inside abstract class all variable are static and all methods are abstract.
For today we have seen the total concepts on OOPS. see you in next class guys.
No comments:
Post a Comment