(8-1)根据提示补全程序空白处,使程序能够正确运行。
1. 定义类Base
package cn.edu.jsu;
public class Base {
① void show() {
System.out.println("你好,中国!");
}
}
2. 定义测试类Demo
package per.cn.edu.jsu;
import cn.edu.jsu.Base;
public class Demo {
public static void main(String[] args) {
Base.show();
}
}
1. 定义类Base
package cn.edu.jsu;
public class Base {
① void show() {
System.out.println("你好,中国!");
}
}
2. 定义测试类Demo
package per.cn.edu.jsu;
import cn.edu.jsu.Base;
public class Demo {
public static void main(String[] args) {
Base.show();
}
}
举一反三
- (8-2)(1)在包中qzy.jsu定义了如下类Base; package qzy.jsu; class Base{ public void show1() { } protected void show2() { } void show3() { } private voidshow4(){}; } (2)在包中qzy.student定义了类Sub,则①处的正确代码是( )。 package qzy.student; import qzy.jsu.*; public class Sub extends Base{ public void show() { ① } }
- (9-4)请根据提示补全程序空白处,使程序能够正确运行。 public class Demo { static void show() throws ① { System.out.println("抛出异常!"); throw new IllegalAccessException("一个异常"); } public static void main(String []args) { try { show(); }catch( ② e ) { e.printStackTrace(); } } }
- 下列程序运行结果是( ) public class Demo { public static void main(String[] args) { Demo demo = new Demo(); demo.show(new Car() { public void run() { System.out.println("demo run"); } }); } public void show(Car c) { c.run(); } }abstract class Car { public void run() { System.out.println("car run..."); } }
- 下列程序运行结果是 public class Demo { public static void main(String[] args) { Object obj=new Father(){ public void show(){ System.out.println("helloworld"); } }; obj.show(); } } class Father{ public void show(){ System.out.println("hello father"); } }
- 如何能使程序调用Base类的构造方法输出"base constructor"; class Base{ Base(int i){ System.out.println("base constructor"); } Base(){ } } public class Sup extends Base{ public static void main(String argv[]){ Sup s= new Sup(); //One } Sup() { //Two } public void derived() { //Three } }