0
点赞
收藏
分享

微信扫一扫

abstract class CBase{ public abstract void say_sth();

GG_lyf 2023-06-18 阅读 21


package Test;

public class hello {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String arg1="world!";
		System.out.printf("hello %s\n", arg1);
		CBase obj;
		obj=new CDerive1();
		obj.say_sth();
		obj.say_hello();
		obj=new CDerive2();
		obj.say_sth();		
		obj.say_hello();
	}

}

abstract class CBase{
public abstract void say_sth();
public void say_hello()
{
System.out.printf("CBase::say_hello\n");
}
}

class CDerive1 extends CBase{
@Override
public void say_sth()
{
System.out.printf("CDerive1\n");
}
}

class CDerive2 extends CBase{
@Override
public void say_sth()
{
System.out.printf("CDerive2\n");
}
}





hello world!
CDerive1
CBase::say_hello
CDerive2
CBase::say_hello

举报

相关推荐

0 条评论