JAVA编程题!速度要!好的再加分!

1、创建一个学生类Student,该类有一个静态变量班费classFee,创建多个学生对象,其中一个对象修改班费属性后,其他对象访问班费属性,观察会出现什么效果?
2、编写一个圆环类Ring,该类有2个成员变量内半径innerRadius和outerRadius外半径,同时有2个方法获取圆环面积getArea()和获取外圆周长getOuterLength()。静态变量的创建,丰富Ring类,创建静态变量pi=3.14。
3、创建一个Mather类,该类有多个洗衣服wash()方法(多态,方法的重载),根据传递的参数类型不同,洗不同人的衣服。

第1个回答  2009-03-31
public class TestStudent {
public static void main(String args[])
{
Student s1=new Student();
Student s2=new Student();
Student s3=new Student();
Student s4=new Student();
s1.classfee=10;
s1.Student();
s2.classfee=20;
s2.Student();
s3.classfee=30;
s3.Student();
s4.classfee=40;
s1.Student();
s2.Student();
s3.Student();
s4.Student();
}
}
class Student
{
public void Student()
{
System.out.println("the classfee is "+classfee);
}
static int classfee=5;
}
还是自己练一练比较好,运行结果显示了静态变量的特性,自己看看。
public class Ring {
public static void main(String args[])
{
double innerRadius=2.5,outerRadius=3.5;
Ring s=new Ring();
s.getArea(innerRadius, outerRadius);
s.getOuterLength(innerRadius, outerRadius);
}

static double pi=3.14;
public void getArea(double innerRadius,double outerRadius)
{
double area=pi*(outerRadius-innerRadius)*(outerRadius+innerRadius);
System.out.println("The area is "+area);

}
public void getOuterLength(double innerRadius,double outerRadius)
{
double length=2*pi*outerRadius;
System.out.println("The length is "+length);

}
}
第二题

public class TestStudent {
public static void main(String args[])
{
TestStudent s1=new TestStudent(new Person1());
TestStudent s2=new TestStudent(new Person2());
TestStudent s3=new TestStudent(new Person3());

}
public TestStudent(Person1 s1)
{System.out.println("Person1 is called.");}
public TestStudent(Person2 s2)
{System.out.println("Person2 is called.");}
public TestStudent(Person3 s3)
{System.out.println("Person3 is called.");}

}
class Person1{}
class Person2{}
class Person3{}
我是初学,编程还是要多练才有进步。
第2个回答  2009-03-31
问题一,因为班费是静态变量,也就是它在内存中的存储位置不变,也就是所有的对象都访问这一个变量,如果一个对象修改了班费,那么别的访问,就是修改后的结果。
剩下的都是基础题,就不啰唆了。本回答被提问者采纳
第3个回答  2009-03-31
与其等待别人的答案,还不如自己动手
况且分那么少
第4个回答  2009-03-31
呵呵,看来贴主是个懒惰的程序员.....