11. public enum Title {  12. MR(”Mr.”), MRS(”Mrs.”), MS(”Ms.”);  13. private final String title;  14. private Title(String t) { title = t; }  15. public String format(String last, String first) {  16. return title + “ “ + first + “ “ + last;  17. }  18. 

题目

11. public enum Title {  12. MR(”Mr.”), MRS(”Mrs.”), MS(”Ms.”);  13. private final String title;  14. private Title(String t) { title = t; }  15. public String format(String last, String first) {  16. return title + “ “ + first + “ “ + last;  17. }  18. }  19. public static void main(String[] args) {  20. System.out.println(Title.MR.format(”Doe”, “John”));  21. }  What is the result?() 

  • A、 Mr. John Doe
  • B、 An exception is thrown at runtime.
  • C、 Compilation fails because of an error in line 12.
  • D、 Compilation fails because of an error in line 15.
  • E、 Compilation fails because of an error in line 20.

相似考题
更多“11. public enum Title {  12. MR(”Mr.”), MRS(”Mrs.”), MS(”Ms.”);  13. private final String title;  14. private Title(String t) { title = t; }  15. public String format(String last, String first) {  16. return title + “ “ + first + “ “ + last;  17. }  18. }”相关问题
  • 第1题:

    11.publicenumTitle{12.MR(”Mr.”),MRS(”Mrs.”),MS(”Ms.”);13.privatefinalStringtitle;14.privateTitle(Stringt){title=t;}15.publicStringformat(Stringlast,Stringfirst){16.returntitle++first++last;17.}18.}19.publicstaticvoidmain(String[]args){20.System.out.println(Title.MR.format(”Doe”,John”));21.}Whatistheresult?()

    A.Mr.JohnDoe

    B.Anexceptionisthrownatruntime.

    C.Compilationfailsbecauseofanerrorinline12.

    D.Compilationfailsbecauseofanerrorinline15.

    E.Compilationfailsbecauseofanerrorinline20.


    参考答案:A

  • 第2题:

    阅读以下说明和Java代码,回答问题

    [说明]

    在某些系统中,存在非常复杂的对象,可以采用循序渐进的方式进行组合将小对象组合,成复杂的对象。

    以下实例展示了Builder(生成器)模式。该实例用来建立“文件”,文件内容包括:一个标题、一串字符以及一些有项目符号的项目。Builder类规定组成文件的方法,Director类利用这个方法产生一份具体的文件。图6-1显示了各个类间的关系。

    以下是Java语言实现,能够正确编译通过。

    [Java代码]

    //Builder. java文件

    public (1) class Builder {

    public abstract void makeTitle(String title);

    public abstract void makeString(String str);

    public abstract void makeItems(String[] items);

    public abstract Object getResult();

    }

    //Director. java文件

    public class Director{

    private (2) builder;

    public Director(Builder builder){

    this. builder = builder;

    }

    public Object construct(){

    builder.makeTitle("Greeting");

    builder.makeString("从早上到白天结束");

    builder.makeItems(new String[]{"早安", "午安",});

    builder.makeString("到了晚上");

    builder.makeItems(new String[]("晚安", "好梦",});

    return builder.getResult();

    }

    }

    //TextBuilder.java文件

    public class TextBuilder (3) Builder{

    private StringBuffer buffer = new StringBuffer();

    public void makeTitle(String title){

    buffer.append("『" + title + "』"\n\n");

    }

    public void makeString(String str){

    buffer.append('■' + str + "\n\n ");

    }

    public void makeItems(String[] items){

    for(int i = 0; i< (4) ; i++){

    buffer.append('·' + items[i] + "\n");

    }

    buffer.append("\n");

    }

    public Object getResult(){

    return buffer.toString();

    }

    }

    //Main.java文件

    public class Main {

    public static void main(String[] args) {

    Director director = new Director(new TextBuilder());

    String result = (String)director. (5) ;

    System.out.println(result);


    正确答案:abstract Builder extends items.length construct()
    abstract Builder extends items.length construct()

  • 第3题:

    下面的代码实现一个简单的Applet: import java.applet.Applet; import java.awt.*; public class Sample extends Applet { private String text="Hello World"; public void init() { add(new Label(text)); } public Sample(String string) { text=string; } } 通过下面的HTML文件访问: <html> <title>Sample Applet</title> <body> <applet code="Sample.class"width=200 height=200></applet> </body> </html> 当编译和运行该小程序时会出现什么结果,请选择正确的答案。( )

    A.将会出现“Hello World"

    B.将会产生一个运行时错误

    C.什么都没有

    D.产生一个编译时错误


    正确答案:D
    解析:该题考查对Applet具体编程的理解。实际上就是考查APplet编程与 Application编程的区别。在应用程序编程中,通常由主类的构造函数和main()方法,在主类的构造函数里面进行一些一次性的初始化工作。而在小程序的编程中,也有主类,既然有类也就有相应的构造函数。但是要知道,Applet是在浏览器或者是通过专门的工具运行的,在创建Applet时,不能通过任何手段给Applet传递参数,所以构造函数应该是不能有参数的。但是,这种错误在编译时并不报错,因为它并没有任何的语法错误,只是会在运行时出错,系统会告诉你无法实例化小程序。注意,本题如果将构造函数改成下面的形式,则编译与运行时都不会出错。public Sample (String string){text="aaaaa";}它的效果与将语句text="aaaaa"放在init()函数里的效果是—样的。也就是说,创建Applet时的初始化工作能放在构造函数里实现的,完全可以放到init()函数里实现。但是,反之,能在init()函数里实现的代码却不一定能在构造函数里实现。这也就是为什么在小程序编程中不用构造函数的原因。故本题答案是D。

  • 第4题:

    在当前坐标系的顶部加一个文本串string的命令是()。

    • A、title(‘string’)
    • B、tilte(‘text’)
    • C、title

    正确答案:A

  • 第5题:

    11. public void testIfA() {  12. if(testIfB(”True”)) {  13. System.out.println(”True”);  14. } else {  15. System.out.println(”Not true”);  16. }  17. }  18. public Boolean testIfB(String str) {  19. return Boolean.valueOf(str);  20. }  What is the result when method testIfA is invoked?() 

    • A、 True
    • B、 Not true
    • C、 An exception is thrown at runtime.
    • D、 Compilation fails because of an error at line 12.
    • E、 Compilation fails because of an error at line 19.

    正确答案:A

  • 第6题:

    11. public static void main(String[] args) {  12. Object obj = new Object() {  13. public int hashCode() {  14. returns 42; 15. }  16. };  17. System.out.println(obj.hashCode());  18. }    What is the result? () 

    • A、 42
    • B、 An exception is thrown at runtime.
    • C、 Compilation fails because of an error on line 12.
    • D、 Compilation fails because of an error on line 16.
    • E、 Compilation fails because of an error on line 17.

    正确答案:A

  • 第7题:

    11. class Animal { public String noise() { return “peep”; } }  12. class Dog extends Animal {  13. public String noise() { return “bark”; }  14. }  15. class Cat extends Animal {  16. public String noise() { return “meow”; }  17. }  .....  30. Animal animal = new Dog();  31. Cat cat = (Cat)animal;  32. System.out.printIn(cat.noise());  What is the result?() 

    • A、 peep
    • B、 bark
    • C、 meow
    • D、 Compilation fails.
    • E、 An exception is thrown at runtime.

    正确答案:E

  • 第8题:

    11. class Person {  12. String name = “No name‟;  13. public Person(String nm) { name = nm; }  14. }  15.  16. class Employee extends Person {  17. String emplD = “0000”;  18. public Employee(String id) { empID = id; }  19. }  20.  21. public class EmployeeTest {  22. public static void main(String[] args) {  23. Employee e = new Employee(”4321”);  24. System.out.println(e.empID);  25. }  26. }  What is the result?() 

    • A、 4321
    • B、 0000
    • C、 An exception is thrown at runtime.
    • D、 Compilation fails because of an error in line 18.

    正确答案:D

  • 第9题:

    10. public class Hello {  11. String title;  12. int value;  13. public Hello() {  14. title += “ World”;  15. }  16. public Hello(int value) {  17. this.value = value;  18. title = “Hello”;  19. Hello();  20. }  21. }  and:  30. Hello c = new Hello(5);  31. System.out.println(c.title);  What is the result?() 

    • A、 Hello
    • B、 Hello World
    • C、 Compilation fails.
    • D、 Hello World 5
    • E、 The code runs with no output.
    • F、 An exception is thrown at runtime.

    正确答案:C

  • 第10题:

    public class ClassA {  public int getValue() {  int value=0;  boolean setting = true;  String title=”Hello”;  (value || (setting && title == “Hello”)) { return 1; }  (value == 1 & title.equals(”Hello”)) { return 2; }  }  } And:  ClassA a = new ClassA();  a.getValue();  What is the result?() 

    • A、 1
    • B、 2
    • C、 Compilation fails.
    • D、 The code runs with no output.
    • E、 An exception is thrown at runtime.

    正确答案:C

  • 第11题:

    You are developing a Windows Communication Foundation (WCF) REST service to provide access to a library book catalog. The following code segment defines the service contract. (Line numbers are included for reference only.) 01 [ServiceContract( )] 02 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 03 public Class LibraryService 04 { 05 public Book GetBookByTitle(string title) 06 { 07 ... 08 } 09 10 [WebGet(UriTemplate = "Book/{id}")] 11 public Book GetBookById(string id) 12 { 13 ... 14 } 15 }Library patrons want the ability to search the catalog by title.You need to ensure that the GetBookByTitle method is exposed as a service method.Which code segment should you insert at line 04?()

    • A、[WebGet(UriTemplate = "Book/{title}")]
    • B、[WebGet(UriTemplate = "BookByTitle/{title}")]
    • C、[WebGet(UriTemplate = "Book/{titleToSearch}")]
    • D、[WebGet(UriTemplate = "{titleToSearch}")]

    正确答案:B

  • 第12题:

    单选题
    public class ClassA {  public int getValue() {  int value=0;  boolean setting = true;  String title=”Hello”;  (value || (setting && title == “Hello”)) { return 1; }  (value == 1 & title.equals(”Hello”)) { return 2; }  }  } And:  ClassA a = new ClassA();  a.getValue();  What is the result?()
    A

     1

    B

     2

    C

     Compilation fails.

    D

     The code runs with no output.

    E

     An exception is thrown at runtime.


    正确答案: D
    解析: 暂无解析

  • 第13题:

    阅读下面代码 abstract class Person { public Person(String n) { name=n; } public______String getDescription(); public String getName() { return name; } private String name; } 在下画线处应填入的修饰符是

    A.static

    B.abstract

    C.protected

    D.final


    正确答案:B

  • 第14题:

    为使下列代码正常运行,应该在下画线处填入的选项是( )。 abstract class person{ public Person(String n){ name=n: } Public String getDescription; public String getName{ return name; } private string name; }

    A.static

    B.private

    C.abstract

    D.final


    正确答案:C
    C。【解析】抽象类中的抽象方法可以只声明,定义延迟到其子类。

  • 第15题:

    The way in which people address each other depends on their age, sex, social group and personal relationship. The English system of address forms frequently used includes first name, last name, title+last name, (), and kin term.

    • A、title+first name
    • B、title+title
    • C、title alone
    • D、first name+last name+title

    正确答案:C

  • 第16题:

    public class Employee{   private String name;   public Employee(String name){   this.name = name;  }   public String getName(){   return name;  }  }   public class Manager extends Employee{   private String department;   public Manager(String name,String department){   this.department = department;   super(name); (应于上一行掉位置)   System.out.println(getName());  }  }   Super的位置是否在方法的首行   执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()

    • A、 smith
    • B、 null
    • C、 SALES
    • D、 编译错误

    正确答案:D

  • 第17题:

    public class Employee{       private String name;  public Employee(String name){           this.name = name;      }  public String getName(){         return name;      } }  public class Manager extends Employee{       private String department;  public Manager(String name,String department){          this.department = department;          super(name);  System.out.println(getName());      }  }  执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?() 

    • A、 smith
    • B、 null
    • C、 SALES
    • D、 编译错误

    正确答案:D

  • 第18题:

    1. public class Test { 2. public static String output =””; 3.  4. public static void foo(int i) { 5. try { 6. if(i==1) { 7. throw new Exception(); 8. } 9. output += “1”; 10. } 11. catch(Exception e) { 12. output += “2”; 13. return; 14. } 15. finally { 16. output += “3”;17. } 18. output += “4”; 19. } 20.  21. public static void main(String args[]) { 22. foo(0); 23. foo(1); 24.  25. }26. } What is the value of the variable output at line 23?()


    正确答案:13423

  • 第19题:

    final class Tree {  private static String tree = "tree ";  String getTree() { return tree; }  }  class Elm extends Tree {  private static String tree = "elm "; public static void main(String [] args) {  new Elm().go(new Tree());  }  void go(Tree t) {  String s = t.getTree()+Elm.tree+tree+(new Elm().getTree());  System.out.println(s);  } }  结果为:() 

    • A、elm elm elm elm
    • B、tree elm elm elm
    • C、tree elm tree elm
    • D、编译失败

    正确答案:D

  • 第20题:

    1. class A {  3. public String to String() {  4. return “4”;  5. }  6. }  7. class B extends A {  8. public String toString() { 9. return super.toString() + “3”;  10. }  11. }  12. public class Test {  13. public static void main (String[] args) {  14. System.out.printIn(new B()); 15. }  16. }   What is the result( )?  

    • A、 Compilation succeeds and 4 is printed.
    • B、 Compilation …………… is printed.
    • C、 An error on line 9 cause compilation to fail.
    • D、 An error on line 14 cause compilation to fail.
    • E、 Compilation succeeds but an exception is thrown at line 9.

    正确答案:B

  • 第21题:

    public class NamedCounter {  private final String name;  private int count;  public NamedCounter(String name) { this.name = name; }  public String getName() { return name; }  public void increment() { coount++; }  public int getCount() { return count; } public void reset() { count = 0; } }  Which three changes should be made to adapt this class to be used safely by multiple threads? ()

    • A、 declare reset() using the synchronized keyword
    • B、 declare getName() using the synchronized keyword
    • C、 declare getCount() using the synchronized keyword
    • D、 declare the constructor using the synchronized keyword
    • E、 declare increment() using the synchronized keyword

    正确答案:A,C,E

  • 第22题:

    11. public static void test(String str) {  12. if(str == null | str.lellgth() == 0) {  13. System.out.println(”String is empty”);  14. } else {  15. System.out.println(”String is not empty”);  16. }  17. }  And the invocation:  31. test(llull);  What is the result?() 

    • A、 Au exception is thrown at runtime.
    • B、 “String is empty” is printed to output.
    • C、 Compilation fails because of au error in line 12.
    • D、 “String is not empty” is printed to output.

    正确答案:A

  • 第23题:

    单选题
    11. class Animal { public String noise() { return “peep”; } }  12. class Dog extends Animal {  13. public String noise() { return “bark”; }  14. }  15. class Cat extends Animal {  16. public String noise() { return “meow”; }  17. }  .....  30. Animal animal = new Dog();  31. Cat cat = (Cat)animal;  32. System.out.printIn(cat.noise());  What is the result?()
    A

     peep

    B

     bark

    C

     meow

    D

     Compilation fails.

    E

     An exception is thrown at runtime.


    正确答案: E
    解析: 暂无解析