Java/creation of object in interface
akash kumar wrote at 2013-08-25 12:49:08
i was totally confused about the concept of interface but right now it's clear and the points are following which define about the interface
#interface is define as the class in method are given but they are not define(it's mean that the method are not inline.they are terminate after there declration)
#in simple word we can say that the methods are only declare into the interface but they do not have information about it.
#class which want to use the interface use the keyword "implement" into it.
#the class define the method of interface in it's own word.
i.e we want to calculate the area of rectangle and circle. so we have followings role interface implemented
1st STEP- we create a interface which have the method which take the two value into it and its return type is float ie float computeArea(float x,float y);
this is the method into the interface created.
2nd STEP- in dis step we create the two class which is rectangle and circle which define the method of computeArea() in its own style.
eg- for rectangle public float computeArea(float x,float y)
also for the circle public float computeArea(float x,float y)
return(pi*x*x);// in the area of circle its point to be noted that we only pass the radius but our function has two value to recive so we
pass the only the first argument as radius and the sceond as 0;
3rd STEP we create the object of each class that is of rectangle and circle.
4th STEP then we create the object refrence by only saying interface name and the refrence name
ie Area area;//refrence created .
5th STEP then we assign the value of rectangle object to the interface refrence
ie area=rect;// rect is the object of rectangle class after dis the area refer to rect object
6th STEP after dis we call the class rectangle by saying the name interface name following by the dot operator computeArea(argument pass )
7th STEP so its way the interface work