Encapsulation
Encapsulation Advantages:
Security
Easy to enhance
Maintainability
Modularity
Security
Easy to enhance
Maintainability
Modularity
Example:
class Sample
{
public int i=10;
public int getId()
{
{
public int i=10;
public int getId()
{
return i;
}
public void setId(int x)
{
}
public void setId(int x)
{
this.i=x;
}
}
}
}
The major limitations od encapsulation is,it increases the code (because we have to getter and setter methods for the data variables )and hence slows down the execution.
Tightly encapsulated class:
A class is said to be tightly encapsulated if and only if data members as the private
Check whether the fallowing classes are tightly encapsulated or not.
a)
class A
{
private int x=10;
public void setX(int x)
{
this.x=x;
}
public int getX()
{
return x;
} ------------------//tightly encapsulated
b). class A{ private int y=10;} -----//tightly encapsulated
c). class A{ private int x=20;} ----// A is tightly encapsulated, B is not
class B extends A{ private int y=30;}
d). class A{ int y=20;}
class B extends A{ private int z=40;}
class C extends B { private int l=50; }
• If the parent class is not tightly encapsulated no child class is tightly encapsulated.
private int x=10;
public void setX(int x)
{
this.x=x;
}
public int getX()
{
return x;
} ------------------//tightly encapsulated
b). class A{ private int y=10;} -----//tightly encapsulated
c). class A{ private int x=20;} ----// A is tightly encapsulated, B is not
class B extends A{ private int y=30;}
d). class A{ int y=20;}
class B extends A{ private int z=40;}
class C extends B { private int l=50; }
• If the parent class is not tightly encapsulated no child class is tightly encapsulated.
4 comments:
I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post I would like to read this
Data Science training in Chennai
Data science training in Bangalore
Data science training in pune
Data science online training
Data Science Interview questions and answers
Data science training in bangalore
Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.
Data Science Training in Chennai
Robotic Process Automation Training in Chennai
Cloud Computing Training in Chennai
Data Warehousing Training in Chennai
Dev Ops Training in Chennai
I ‘d mention that most of us visitors are endowed to exist in a fabulous place with very many wonderful individuals with very helpful things.
Best PHP Training Institute in Chennai|PHP Course in chennai
Best .Net Training Institute in Chennai
Matlab Training in Chennai
Embedded Training in Chennai
SAS Training in Chennai
Post a Comment