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.A powerful way to manage abstraction is through hierarchical classification. This allows us to layer the semantics of complex systems by breaking them more manageable pieces. Hierarchical abstractions of complex systems can also be applied to computer programs. The data from a traditional process oriented program can be transform by abstractions into it component object. A sequence of process steps can become a collection of messages between these objects. Thus each of these objects describes its unique behavior. We can create this objects as concrete entities that respond to messages, telling them to do something. This is the essence of object oriented programming.
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