| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 193 人关注过本帖
标题:[求助]包中的类为什么不能引入?
取消只看楼主 加入收藏
虚景
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-10-15
收藏
 问题点数:0 回复次数:0 
[求助]包中的类为什么不能引入?

本人一java新手,碰到以下问题,请各为大侠不吝赐教,在这里先谢过了!
包文件:
package package1;
//接口 面积
interface shape_area
{
void area();
}
//抽象类 shape
abstract class shape
{
abstract void width();
}
//类 矩形
class rectangle extends shape implements shape_area
{
public double wid;
public double len;
rectangle(double x,double y)
{
wid=x;
len=y;
}
public void width()
{
System.out.println("The rectangle's area is "+(wid+len)*2);
}

public void area()
{
System.out.println("The rectangle's area is "+wid*len);
}
}
// 类 三角形
class triganle extends shape implements shape_area
{
double x,y,z;
triganle(double a,double b,double c)
{
x=a;
y=b;
z=c;
}
public void width()
{
System.out.println("The triangle's wid is "+(x+y+z));
}

public void area()
{
double d;
d=(x+y+z)/2;
System.out.println("The triangle's area is "+Math.sqrt(d*(d-x)*(d-y)*(d-z)));
}
}
//类 圆
class circle extends shape implements shape_area
{
double radius;
circle(double x)
{
radius=x;
}
public void area()
{
System.out.println("The area of the circle is "+3.14*radius*radius);
}
public void width()
{
System.out.println("The width of the circle is "+3.14*2*radius);
}
}
//类 四边型
class polygon extends shape implements shape_area
{
double m,n,p,q;//四条边的长度
double x;
polygon(double a,double b,double c,double d,double e)
{
m=a;n=b;p=c;q=d;x=e;
}

public void area()
{
double d,sum=0;
d=(m+n+x)/2;
sum+=Math.sqrt(d*(d-m)*(d-n)*(d-x));
d=(p+q+x)/2;
sum+=Math.sqrt(d*(d-p)*(d-q)*(d-x));
System.out.println("The area of the polygon is "+sum);
}
public void width()
{
System.out.println("The width of the polygon is "+m+n+q+p);
}
}


使用包的文件:
import package1.*;
class graphshape
{
public static void main(String args[])
{
rectangle rec1=new rectangle(2.0,3.0);
rec1.area();
circle cir1=new circle(2.0);
cir1.area();
triganle tri1=new triganle(3.0,4.0,5.0);
tri1.width();
polygon pol1=new polygon(5,6,7,8,9);
pol1.area();
pol1.width();
}
}
错误:
The type rectangle is not visible
The type circle is not visible
The type triganle is not visible
The type polygon is not visible


2007-10-20 13:44
快速回复:[求助]包中的类为什么不能引入?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017734 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved