abstract class Person//抽象类
{
String info[];//属性
String age;
String name;
public abstract void setInfo(String a,String b,String c,String d);//抽象方法
public abstract String getInfo();//抽象方法
public void output()//输出函数
{
System.out.println(this.getInfo());
};
}
class Teacher extends Person//继承抽象类
{
String salary;
String tnumber;
public void setInfo(String name,String age,String tnumber,String salary)//用参数初始化类中的属性
{
this.name=name;
this.age=age;
this.tnumber=tnumber;
this.salary=salary;
}
public String getInfo()//返回信息
{
return (name+ age+tnumber+salary);
}
}
public class Demo7
{
public static void main(String agrs[])
{
Teacher tea=new Teacher();
tea.setInfo("张三","22","2010001","4500");//初始化属性
tea.output();//输出
}
}
class person
{
private String name;
private int age;
public person(){ }//构造函数
public person(String name)//重载构造函数
{
this.name=name;
}
public person(String name,int age)
{
this.name=name;
this.age=age;
}
public String toString()//输出函数
{
return "姓名"+name+",年龄"+age;
}
}
public class Demo2
{
public static void main(String args[])
{
person p1=new person();
person p2=new person("刘丽");
person p3=new person("丽丽",18);
System.out.println(p1.toString());
System.out.println(p2.toString());
System.out.println(p3.toString());
}
}
class person
{
String name;
String age;
public person(String name,String age)
{
this.name=name;
this.age=age;
}
public String toString()
{
return "姓名:"+name+",年龄"+age;
}
public boolean equals(Object obj)
{
if(this==obj)//判断是不是person类的对象
{
return true;
}
person per=(person)obj;//将对象信息保存在per
if(!(obj instanceof person))
return false;
if(per.name.equals("liuli")&&this.age.equals("21"))
{
return true;
}
else
{
return false;
}
}
}
public class Demo8
{
public static void main(String args[])
{
//person per=(person)obj;
//person per=new person("刘丽","21");
person per1=new person("liuli","21");
person per2=new person("lili","21");
if(per1.equals(per2))
{
System.out.println("是同一个对象"+per1);
}
else
{
System.out.println("不是同一个对象");
}
System.out.println("person");
//System.out.println(per.toString());
}
}