GoConqr has a new look! Let us know what you think.

Notes

Superclass Example 1

joannazhang13 English 1 page

Content of the notes (1)

Page 1

public class Circle extends Shape

{

private double radius;

//constructor

public Circle (double r, String name)

{

super(name);

radius= r;

}

public double getRadius()

{

return radius;

}

public double perimeter()

{

return 2*Math.PI*radius;

}

public double area()

{

return Math.PI*Math.pow(radius, 2);

}

public int compareTo(Shape s)

{

if (s.getName()==name

{

if(s.getRadius()==radius)

return 0;

else if(s.getRadius()> radius)

return -1;

else

return 1;

}

else

return -2;

}

}

Information

Description
Example code of Java superclass
Created by
joannazhang13 · May 2015
Updated
Feb 20, 2016
Views
34
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?