第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{}
我是初学,编程还是要多练才有进步。