继承
- 作业要求
设计一个类LowCaseLetter,该类的对象可以调用outLetter ( )方法输出小写英文字母表,再设计该类的子类,要求子类必须继承父类的outLowcaseLetter方法,子类还须新增方法outUpcaseLetter ( )输出大写字母,并设计主类L etterOutVariation,在其main ( )方法中测试上述两个类LowCaseLetter和LowCaseLetter。
- 实验步骤
package jicheng;
public class LowCaseLetter
{
public void outLetter ()
{
System.out.println("asdfsdf");
}
}
package jicheng;
public class LowCaseLetter extends LowCaseLetter
{
public void outUpcaseLetter ()
{
System.out.println("ASD");
}
//方法的重写
public void outLetter ()
{
System.out.println("重写的方法");
}
}
package jicheng;
public class LetterOutVariation
{
public static void main(String[] args)
{
LowCaseLetter c=new LowCaseLetter ();
c.outLetter ();
B c1=new LowCaseLetter ();
c1.outUpcaseLetter ();
c1.outLetter ();
}
}
- 实验结果