14_static_packages

Or rectangle class name conflicts eg with

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ༆  They are related, so it makes sense to group them together Somebody else may have created a Shape or Rectangle class – name conflicts (e.g. with java.awt.Rectangle) Classes within a package can be allowed to have unrestricted access to one another yet still restrict access outside the package. Package: a named collection of related classes that are grouped in a directory (the name of the directory is the same as the name of the package). Creating a Java Package Rectangle.java Shape.java package shapes; public abstract class Shape { int x,y; public Shape(int x, int y){ this.x = x; this.y = y; } } Circle.java package shapes; public class Rectangle extends Shape { double width, height; public Rectangle(int x, int y, double h, double w ) { super(x, y); width = w; height = h; } } package shapes; public class Circle extends Shape { double radius; public Circle(int x, int y, double r) { super(x, y); radius = r; } } Using p...
View Full Document

Ask a homework question - tutors are online