构造方法也需要返回值类型吗? ******谢! 写了那么的方法是否有点重复,能否就重要的几种详细说明
class Person {
String name;
int age;
static int x;
Person( String n,int a)
{
name = n;
age = a;
}
Person( String n)
{
name = n;
age =-1;
}
Person( int age,String name)
{
this.age = age;
this.name = name;
}
Person()
{
this(0,"");
}
void sayHello()
{
System.out.println("Hello!My name is"+ name);
}
void sayHello( Person another)
{
System.out.println("Hello,"+another.name+"!My name is "+name);
}
boolean isOlderThan( int anAge)
{
bloolean flg;
if( age> anAge ) flg=true; else flg=false;
return flg;
}
public static void main (String[] args)
{
System.out.println("Hello World!");
}
class Student extends Person
{
String school;
int score;
//void sayHello(){
//System.out.println("Hello! My name is "+ name+ ".My school is"+ school);//}
}
void sayHello( Student another)
{
System.out.println("Hi");
if(school==another.school) System.out.println("Schoolmate");
}
boolean isGoodStudent()
{
return score>=90;
}
void testThisSuper()
{
a = age;
a = this.age;
a = super.age;
}
void sayHello()
{
super.sayHello();
System.out.println("My school is" +school);
}
Student(String name,int age,String school)
{
super(name, age);
this.school = school;
}
Student(){}
public void main( String [] args)
{
Person p = new Person("Liming",50);
Student s = new Student("Wangqiang",20,"PKU");
Person p2 = new Student("Zhangyi",18,"THU");
Student s2 = (Student) p2;
}
}