java小白的学习记录......
1. 首先看实例
1)父类
public class SeniorClass
{
public SeniorClass()
{
System.out.println("父类构造方法");
toString(); //父类的构造方法调用toString()
}
public String toString()
{
System.out.println("Senior");
return "Senior";
}
}
2)子类
public class JuniorClass extends SeniorClass
{
private String name;
public JuniorClass()
{
super(); //调用父类的构造方法
System.out.println("子类构造方法");
name="Junoir";
}
public String toString() //覆写父类的toString()
{
System.out.println(name);
return name.toUpperCase();
}
}
3)测试
public class Test
{
public static void ma