Which two allow the class Thing to be instantiated using new Thing()?
A: public class Thing { }
B: public class Thing { public Thing() {} }
C: public class Thing { public Thing(void) {} }
D: public class Thing { public Thing(String s) {} }
E: public class Thing { public void Thing() {} public Thing(String s) {} }
A: public class Thing { }
B: public class Thing { public Thing() {} }
C: public class Thing { public Thing(void) {} }
D: public class Thing { public Thing(String s) {} }
E: public class Thing { public void Thing() {} public Thing(String s) {} }
举一反三
- 【单选题】对于下面()类定义,可以通过“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) { } }
- 给定代码如下: public abstract interface Frobnicate { public void twiddle(String s); } 以下哪个类是正确的?(). A: public abstract class Frob implements Frobnicate { public abstract void twiddle(String s) { } } B: public abstract class Frob implements Frobnicate { } C: public class Frob extends Frobnicate { public void twiddle(Integer i) { } } D: public class Frob implements Frobnicate { public void twiddle(Integer i) { } }
- 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(); } } 该程序将( )。
- 从下面四段代码中选择出正确的代码段() A: public class Something {public static void main(String[] args) {Other o = new Other();new Something().addOne(o);}public void addOne(final Other o) {o.i++;}}class Other {public int i;} B: public class Something {void doSomething () {private String s = ̶”;int l = s.length();}} C: abstract class Name {private String name;public abstract boolean isStupidName(String name) {}} D: public class Something {public int addOne(final int x) {return ++x; }}
- 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); } } 对于以上代码,其运行结果是