Shape Example |
![]() |
![]() |
![]() |
1. Point.java
?public class Point
??? public Point() {
??? public Point(float fX, float fY) {
??? public Point(Point p) {
??? // You will generally not need to write a finalizer. Member variables that
??? public void print() {
?public abstract class Shape
??? public Shape() {
??? public Shape(Point p) {
??? // You will generally not need to write a finalizer.?Member variables that
??? public void print() {
??? // An example of a static member function.
?public class Circle extends Shape
??? public Circle() {
??? public Circle(float fX, float fY, float fRadius) {
??? public Circle(Point p, float fRadius) {
??? // You will generally not need to write a finalizer. Member variables that
??? public void print() {
?public class Square extends Shape
??? public Square() {
??? public Square(float fX, float fY, float fLength) {
??? public Square(Point p, float fLength) {
??? // You will generally not need to write a finalizer.?Member variables that
??? public void print() {
?public class Main
??? public static void main(String[] args)
??????? Point b;
??????? Point c = new Point(b);
??????? // Print out the total number of Shapes created so far.?At this point,
??????? // Create a Circle object and hold on to it using a Shape reference.
??????? // Create an array of Shapes.
??????? shapeArray[0] = new Square();
??????? // Print out the array of Shapes. The length member gives the array size.
??????? // Print out the total number of Shapes created so far. At this point,
??????? // We can mark the objects for destruction by removing all references to
|
地震讓大伙知道:居安思危,才是生存之道。
