网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
单选题
现有: class Pencil { public void write (String content){ System.out.println( "Write",+content){ } }class RubberPencil extends Pencil{ public void write (String content){ System.out.println("Rubber Write"+content); } public void erase (String content)}} 执行下列代码的结果是哪项?() Pencil pen=new Pencil(); (( RubberPencil) pen).write( "Hello");
A
Write Hello
B
Rubber Write Hello
C
编译失败
D
运行时抛出异常
参考答案
参考解析
解析:
暂无解析
更多 “单选题现有: class Pencil { public void write (String content){ System.out.println( "Write",+content){ } }class RubberPencil extends Pencil{ public void write (String content){ System.out.println("Rubber Write"+content); } public void erase (String content)}} 执行下列代码的结果是哪项?() Pencil pen=new Pencil(); (( RubberPencil) pen).write( "Hello");A Write HelloB Rubber Write HelloC 编译失败D 运行时抛出异常” 相关考题
考题
现有:classPencil{publicvoidwrite(Stringcontent){System.out.println(Write,+content){}}classRubberPencilextendsPencil{publicvoidwrite(Stringcontent){System.out.println(RubberWrite+content);}publicvoiderase(Stringcontent)}}执行下列代码的结果是哪项?()Pencilpen=newPencil();((RubberPencil)pen).write(Hello);A.WriteHelloB.RubberWriteHelloC.编译失败D.运行时抛出异常
考题
现有:classPencil{publicvoidwrite(Stringcontent){System.out.println(Write+content);}}classRubberPencilextendsPencil{publicvoidwrite(Stringcontent){System.out.println(RubberWrite+content);}publicvoiderase(Stringcontent){System.out.println(Erase+content);}}执行下列代码的结果是哪项?()Pencilpen=newRubberPencil();pen.write(Hello);A.WriteHelloB.RubberWriteHelloC.编译错误D.运行时抛出异常
考题
interface A{int x = 0;}class B{int x =1;}class C extends B implements A {public void pX(){System.out.println(x);}public static void main(String[] args) {new C().pX();}}
考题
阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图6-1所示的类图。
【java代码】 class invoice{ public void printInvoice(){: System.out.println("This is the content of the invoice!"); } } class Decorator:extends Invoice{ protected Invoice ticket; public Decorator(lnvoice t){ ticket=t; } public void printinvoice(){ if(ticket!=NULL) (1); } } class FootDecorator extends Decorator{ public FootDecorator(lnvoice t){ super(t); } public void printinvoice(){ Systent.out.println("This is the header of the invoice!"); (2); } } class FootDecorator extends Decorator{ public FootDecorator(invoice t):{ super(t); } public void printlnvoice(){ (3); Systent.out.println("This is the header of the invoice!"); } } Class test{ public static void main(string[]args){ Invoice t=new invioce(); Invoice ticket; Ticket=(4); Ticket.Printinvoice(); Systent.out.println(“--------------“) Ticket=(5); Ticket.Printinvoice(); } } 程序的输出结果为: This is the header of the invoice! This is the content of the invoice! This is the footnote of the invoice! ---------------------------- This is the header of the invoice! This is the footnote of the invoice!
考题
阅读下列说明和java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
【说明】
某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图6-1所示的类图。
【java代码】
class invoice{
public void printInvoice( ){
System.out.println ( "This is the content of the invoice!");
}
}
class Decorator extends Invoice {
protected Invoice ticket;
public Decorator(lnvoice t){
ticket = t;
}
public
void printInvoice( ){
if(ticket != null)
(1) ;
}
}
class HeadDecorator extends Decorator{
public HeadDecorator(lnvoice t){
super(t);
}
public void printInvoice ( ){
Systent.out.println( "This is the header of the invoice! ");
(2) ;
}
}
class FootDecorator extends Decorator {
public FootDecorator(Invoice t){
super(t);
}
public void printlnvoice( ){
( 3) ;
Systent.out.println( "This is the footnote of the invoice! ");
}
}
Class test {
public static void main(String[] args){
Invoice t =new Invioce( );
Invoice ticket;
ticket= (4) ;
ticket.printInvoice( );
Systent.out.println(“------------------“);
ticket= (5) ;
ticket.printInvoice( );
}
}
程序的输出结果为:
This is the header of the invoice!
This is the content of the invoice!
This is the footnote of the invoice!
----------------------------
This is the header of the invoice!
This is the footnote of the invoice!
考题
class MyThread extends Thread { public void run() { System.out.println(“AAA”); } public void run(Runnable r) { System.out.println(“BBB”); } public static void main(String[] args) { new Thread(new MyThread()).start(); } } What is the result?() A、 AAAB、 BBBC、 Compilation fails.D、 The code runs with no output.
考题
class Parent { String one, two; public Parent(String a, String b){ one = a; two = b; } public void print(){ System.out.println(one); } } public class Child extends Parent { public Child(String a, String b){ super(a,b); } public void print(){ System.out.println(one + " to " + two); } public static void main(String arg[]){ Parent p = new Parent("south", "north"); Parent t = new Child("east", "west"); p.print(); t.print(); } } Which of the following is correct?()A、 Cause error during compilation. B、 south east C、 south to north east to west D、 south to north east E、 south east to west
考题
现有: class Pencil { public void write (String content){ System.out.println ("Write"+content); } } class RubberPencil extends Pencil{ public void write (String content){ System.out.println ("Rubber Write"+content); } public void erase (String content){ System.out.println ("Erase "+content); } } 执行下列代码的结果是哪项?() Pencil pen=new RubberPencil(); pen.write("Hello"); A、 Write HelloB、 Rubber Write HelloC、编译错误D、运行时抛出异常
考题
public class Employee{ private String name; public Employee(String name){ this.name = name; } public void display(){ System.out.print(name); } } public class Manager extends Employee{ private String department; public Manager(String name,String department){ super(name); this.department = department; } public void display(){ System.out.println(super.display()+”,”+department); } } 执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?() A、 smith,SALESB、 null,SALESC、 smith,nullD、 null,nullE、 编译错误
考题
class Super { public int i = 0; public Super(String text) { i = 1; } } public class Sub extends Super { public Sub(String text) { i = 2; } public static void main(String args[]) { Sub sub = new Sub(“Hello”); System.out.println(sub.i); } } What is the result?() A、 0B、 1C、 2D、 Compilation fails.
考题
class TestA { public void start() { System.out.println(”TestA”); } } public class TestB extends TestA { public void start() { System.out.println(”TestB”); } public static void main(String[] args) { ((TestA)new TestB()).start(); } } What is the result?() A、 TestAB、 TestBC、 Compilation fails.D、 An exception is thrown at runtime.
考题
public class Employee{ private String name; public Employee(String name){ this.name = name; } public void display(){ System.out.print(name); } } public class Manager extends Employee{ private String department; public Manager(String name,String department){ super(name); this.department = department; } public void display(){ System.out.println( super.display()+”,”+department); } } 执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?() A、 smith,SALESB、 null,SALESC、 smith,nullD、 null,null
考题
现有: class Pencil { public void write (String content){ System.out.println( "Write",+content){ } }class RubberPencil extends Pencil{ public void write (String content){ System.out.println("Rubber Write"+content); } public void erase (String content)}} 执行下列代码的结果是哪项?() Pencil pen=new Pencil(); (( RubberPencil) pen).write( "Hello"); A、Write HelloB、Rubber Write HelloC、编译失败D、运行时抛出异常
考题
现有: class Pencil { public void write (String content){ System.out.println ("Write"+content); } } class RubberPencil extends Pencil{ public void erase (String content){ System.out.println ("Erase"+content); } } 执行下列代码的结果是哪项?() Pencil pen=new RubberPencil(); pen.write ("Hello"); pen.erase ("Hello"); A、 Write Hello Erase HelloB、 Erase Hello Write HelloC、编译错误D、运行时抛出异常
考题
现有: class TestA { public void start() { System.out.println("TestA"); } } public class TestB extends TestA { public void start() { System.out.println("TestB"); } public static void main (string[] args) ( ((TestA)new TestB()).start(); ) } 运行结果是哪项?() A、 TeStAB、 TeStBC、编译失败D、运行时抛出异常
考题
Which method implementations will write the given string to a file named "file", using UTF8 encoding?() IMPLEMENTATION a: public void write(String msg) throws IOException { FileWriter fw = new FileWriter(new File("file")); fw.write(msg); fw.close(); } IMPLEMENTATION b: public void write(String msg) throws IOException { OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("file"), "UTF8"); osw.write(msg); osw.close(); } IMPLEMENTATION c: public void write(String msg) throws IOException { FileWriter fw = new FileWriter(new File("file")); fw.setEncoding("UTF8"); fw.write(msg); fw.close(); } IMPLEMENTATION d: public void write(String msg) throws IOException { FilterWriter fw = FilterWriter(new FileWriter("file"), "UTF8"); fw.write(msg); fw.close(); } IMPLEMENTATION e: public void write(String msg) throws IOException { OutputStreamWriter osw = new OutputStreamWriter( new OutputStream(new File("file")), "UTF8" ); osw.write(msg); osw.close(); } A、Implementation a.B、Implementation b.C、Implementation c.D、Implementation d.E、Implementation e.
考题
Given the following code, write a line of code that, when inserted at the indicated location, will make the overriding method in Extension invoke the overridden method in class Base on the current object. class Base { public void print( ) { System.out.println("base"); } } class Extention extends Base { public void print( ) { System.out.println("extension"); // insert line of implementation here } } public class Q294d { public static void main(String args[]) { Extention ext = new Extention( ); ext.print( ); } } Fill in a single line of implementation.()
考题
单选题public class Employee{ private String name; public Employee(String name){ this.name = name; } public void display(){ System.out.print(name); } } public class Manager extends Employee{ private String department; public Manager(String name,String department){ super(name); this.department = department; } public void display(){ System.out.println(super.display()+”,”+department); } } 执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()A
smith,SALESB
null,SALESC
smith,nullD
null,nullE
编译错误
考题
单选题class MyThread extends Thread { public void run() { System.out.println(“AAA”); } public void run(Runnable r) { System.out.println(“BBB”); } public static void main(String[] args) { new Thread(new MyThread()).start(); } } What is the result?()A
AAAB
BBBC
Compilation fails.D
The code runs with no output.
考题
单选题public class Employee{ private String name; public Employee(String name){ this.name = name; } public void display(){ System.out.print(name); } } public class Manager extends Employee{ private String department; public Manager(String name,String department){ super(name); this.department = department; } public void display(){ System.out.println( super.display()+”,”+department); } } 执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()A
smith,SALESB
null,SALESC
smith,nullD
null,null
考题
单选题Which method implementations will write the given string to a file named "file", using UTF8 encoding?() IMPLEMENTATION a: public void write(String msg) throws IOException { FileWriter fw = new FileWriter(new File("file")); fw.write(msg); fw.close(); } IMPLEMENTATION b: public void write(String msg) throws IOException { OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("file"), "UTF8"); osw.write(msg); osw.close(); } IMPLEMENTATION c: public void write(String msg) throws IOException { FileWriter fw = new FileWriter(new File("file")); fw.setEncoding("UTF8"); fw.write(msg); fw.close(); } IMPLEMENTATION d: public void write(String msg) throws IOException { FilterWriter fw = FilterWriter(new FileWriter("file"), "UTF8"); fw.write(msg); fw.close(); } IMPLEMENTATION e: public void write(String msg) throws IOException { OutputStreamWriter osw = new OutputStreamWriter( new OutputStream(new File("file")), "UTF8" ); osw.write(msg); osw.close(); }A
Implementation a.B
Implementation b.C
Implementation c.D
Implementation d.E
Implementation e.
考题
单选题class Super { public int i = 0; public Super(String text) { i = 1; } } public class Sub extends Super { public Sub(String text) { i = 2; } public static void main(String args[]) { Sub sub = new Sub(“Hello”); System.out.println(sub.i); } } What is the result?()A
0B
1C
2D
Compilation fails.
考题
单选题class TestA { public void start() { System.out.println(”TestA”); } } public class TestB extends TestA { public void start() { System.out.println(”TestB”); } public static void main(String[] args) { ((TestA)new TestB()).start(); } } What is the result?()A
TestAB
TestBC
Compilation fails.D
An exception is thrown at runtime.
考题
单选题现有: class TestA { public void start() { System.out.println("TestA"); } } public class TestB extends TestA { public void start() { System.out.println("TestB"); } public static void main (string[] args) ( ((TestA)new TestB()).start(); ) } 运行结果是哪项?()A
TeStAB
TeStBC
编译失败D
运行时抛出异常
考题
单选题class Parent { String one, two; public Parent(String a, String b){ one = a; two = b; } public void print(){ System.out.println(one); } } public class Child extends Parent { public Child(String a, String b){ super(a,b); } public void print(){ System.out.println(one + " to " + two); } public static void main(String arg[]){ Parent p = new Parent("south", "north"); Parent t = new Child("east", "west"); p.print(); t.print(); } } Which of the following is correct?()A
Cause error during compilation. B
south east C
south to north east to west D
south to north east E
south east to west
考题
单选题现有: class Pencil { public void write (String content){ System.out.println ("Write"+content); } } class RubberPencil extends Pencil{ public void write (String content){ System.out.println ("Rubber Write"+content); } public void erase (String content){ System.out.println ("Erase "+content); } } 执行下列代码的结果是哪项?() Pencil pen=new RubberPencil(); pen.write("Hello");A
Write HelloB
Rubber Write HelloC
编译错误D
运行时抛出异常
考题
单选题现有: class Pencil { public void write (String content){ System.out.println ("Write"+content); } } class RubberPencil extends Pencil{ public void erase (String content){ System.out.println ("Erase"+content); } } 执行下列代码的结果是哪项?() Pencil pen=new RubberPencil(); pen.write ("Hello"); pen.erase ("Hello");A
Write Hello Erase HelloB
Erase Hello Write HelloC
编译错误D
运行时抛出异常
热门标签
最新试卷