public class Outer{
class Inner{
public void go(){
System.out.print("hi");
}
}
}
举一反三
- (6-10)有如下代码,请为指定位置选择正确代码。( ) class Outer{ class Inner{ void show() { System.out.println("inner"); } } public void aOuterMethod() { // ① } public static void main(String[] args) { Outer out=new Outer(); // ② Outer.Inner inn=out.new Inner(); // inn.show(); } }
- 有如下类的定义。class A{ public void show() { show2(); } public void show2() { System.out.print("我"); }}class B extends A{ public void show2(){ System.out.print("爱"); }}class C extends B{ public void show() { super.show(); } public void show2() { System.out.print("你"); }}public class Test4 { public static void main(String[] args) { A a=new B(); a.show(); B b=new C(); b.show(); }} A: 我爱你 B: 爱你 C: 我爱 D: 我你
- 如下定义类的语法正确的是? A: public void 类名{} B: public static 类名{} C: public class 类名{} D: public class 类名(){}
- import java.io.*; class Person{ public void print(){System.out.print("Person ");} public void printMyGender(String s){ this.print(); System.out.print(s+" "); } } class Gender{ String type="gender"; public void print(Person p){p.printMyGender(type);} } class Female extends Gender{ public Female(){ type="female"; } } class Male extends Gender{ public Male(){ type="male"; } } class Employee extends Person{ public void print(){ System.out.print("Employee ");} } class Manager extends Employee{ public void print(){ System.out.print("Manager ");} } public class Test{ public static void main(String[] args){ Manager man = new Manager(); Employee em = new Employee(); Gender gender1 = new Male(); Gender gender2 = new Female(); gender1.print(man); gender2.print(em); } } 对于以上代码,其运行结果是
- Java程序如下 class A{ public A(){System.out.print("A");} } class B extends A{ public B(){System.out.print("B");} public static void main(String[]s){ new B(); } } 该程序将( )。
内容
- 0
定义类Block和类Demo,运行Demo的输出结果是。 class Block{ {//代码1 System.out.print("1"); } static{//代码2 System.out.print("2"); } {//代码3 System.out.print("3"); } public Block() {//代码4 System.out.print("4"); } static void show() {//代码5 System.out.print("5"); } static {//代码6 System.out.print("6"); } } //定义测试类Demo public class Demo { public static void main(String[] args) { new Block().show(); new Block() } }
- 1
【单选题】对于下面()类定义,可以通过“new J_Class()”生成类 J_Class 的实例对象。 A. public class J_Class { public J_Class(void) { } } B. public class J_Class { } C. public class J_Class { public J_Class(String s) { } } D. public class J_Class { public void J_Class() { } public J_Class(String s) { } }
- 2
(7-1)定义了如下 的Father类和Derived类,则下面( )语句是正确的。 abstract class Father { public abstract void call(); } class Derived extends Father { public void call() { } }
- 3
下列哪个类声明是正确的( ) A: public void A1{…} B: public class Move(){…} C: public class void number{…} D: public class Car{…}
- 4
如下方法声明中,错误的是() A: public void say(){ System.out.print(“Hi”); } B: public void say(){ System.out.print(“Hi”); return; } C: public int say(){ System.out.print(“Hi”); return; } D: public int say(){ System.out.print(“Hi”); return 0; }