`

java之继承

    博客分类:
  • Java
阅读更多

如下面代码:

 

public class Test
{
	public static void main(String[] args)
	{
		TestA ta = new TestC();
		ta.show();
	}
}

class TestA
{
	public TestA()
	{
		System.out.println("TestA");
	}
	
	public void show()
	{
		System.out.println("TestA.show");
	}
}

class TestB extends TestA
{
	public TestB()
	{
		System.out.println("TestB");
	}
	
	public void show()
	{
		System.out.println("TestB.show");
	}
}

class TestC extends TestB
{
	public TestC()
	{
		System.out.println("TestC");
	}
}

 

 

输出为:

 

TestA
TestB
TestC
TestB.show

 

1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics