Abstraction
An essential element of object oriented programming is abstraction. We manage complexity through abstraction. For example, we don’t think car as a set of tense of thousands of individual parts instead we think of it as a well-defined object, with its own unique behavior. This allows us to driving a car by only learning how to drive and not how the internal components of the car work.
Example:
class Num
{
int n;
Num (int n)
{
this.n= n;
}
boolean is Even()
{
if (n%2==0)
{
return
true;
}
else
{
return
false;
}
}
viod show()
{
System.out.println(n);
}
}
class Evenchecker
{
public static void main (String
[]s)
{
Num a= new Num();
if (a. is even())
{
System.out.println(“Even”);
}
else {
System.out.println(“Odd”);
}
}
}
No comments:
Post a Comment