troubleshooting Question

Interface confusion

Avatar of zizi21
zizi21 asked on
Java
8 Comments1 Solution238 ViewsLast Modified:
Hi,

Studying for exam..Getting cold feet. Forgive me if the question sounds dumb but i really dont understand..

there is code such as :

interface Shape{

void draw();
};

class Circle implements Shape{

private double x,y,radius;

public Circle(double xt,double yt,double rad)
{
x=xt;
y=yt;
radius=rad;
}
public void draw()
{
System.out.println("Circle ....");
}

}

class Square implements Shape{
private double x,y,size;

public Square(double xt,double yt,double size)
{
x=xt;
y=yt;
this.size=size;
}

public void draw()
{
System.out.println("Square ...");
}

}


//THIS IS WHERE THE CONFUSION STARTS..


public class Test{

public static void drawShape(Shape i){
i.draw();
}

public static void main(String []args)
{
Circle aCircle=new Circle(10,10,5);
Square aSquare=new Square(10,10,5);

aCircle.draw();
aSquare.draw();

Test.drawShape(aCircle);
Test.drawShape(aSquare);
}

}

Confusion one:
The static drawShape excepts a Shape object which is an inteface..but we give it a class object..so,i a class is also an interface...pls help..thank you...  
ASKER CERTIFIED SOLUTION
Mick Barry
Java Developer
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros