Superclass Example 1

Description

Example code of Java superclass
joannazhang13
Note by joannazhang13, updated more than 1 year ago
joannazhang13
Created by joannazhang13 over 9 years ago
9
0

Resource summary

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; } }

Show full summary Hide full summary

Similar

Java Week 5 Object Oriented Programming
Troy Bowlin
Superclass Example 2
joannazhang13
Abstract Class Quiz
joannazhang13
What does inheritance do?
joannazhang13
Let's see what you know
joannazhang13
Abstract Class Example
joannazhang13
Subclass Example
joannazhang13
Java Practice 1
Ummm No
Servion - Java Questionnaire
rohit.benedict
Java Practice 2
Ummm No
Java Core. Basics
Gadget