单选题现有:   1. class Book {    2.   private final void read() { System.out.print("book "); }    3. }   4. class Page extends Book {    5.   public static void main(String [] args) {    6.     // insert code here   7.   }    8.   private final void read() { System.out.print("page "); }    9. }    和如下三个代码片段 ( x, y, z ):   x. // just a comment    y. new Page().read();   z. new Book().read();    分别插入到第6行,有几个允许代码通过编译并可以运行且无异常?()A 0B 1C 2D 3

单选题
现有:   1. class Book {    2.   private final void read() { System.out.print("book "); }    3. }   4. class Page extends Book {    5.   public static void main(String [] args) {    6.     // insert code here   7.   }    8.   private final void read() { System.out.print("page "); }    9. }    和如下三个代码片段 ( x, y, z ):   x. // just a comment    y. new Page().read();   z. new Book().read();    分别插入到第6行,有几个允许代码通过编译并可以运行且无异常?()
A

 0

B

 1

C

 2

D

 3


参考解析

解析: 暂无解析

相关考题:

下列哪个类声明是正确的? ( )A.abstract final class H1 {...}B.abstract private move(){...}C.protected private numberD.public abstract class Car{...}

( 12 )请将下面的程序补充完整,使得程序输出 “ 飘是张娜的书 ” 。#include iostreamusing namespace std;class Book{public:Book(char *str) {strcpy(title,str);}【 12 】 void PrintInfo() {couttitleendl;}protected:char title[50];};class MyBook:public Book{public:MyBook(char *s1,char *s2= " 张娜 " ):【 13 】 {strcpy(owner,s2);}virtual void PrintInfo() {couttitle " 是 " owner " 的书 " endl;}private:char owner[10];};int main(){Book *prt=new MyBook( " 飘 " );prt-PrintInfo();return 0;}

下面这个程序的结果是 include class A { private: int a; public: void seta( ) ; 下面这个程序的结果是#include<iostream.h>class A{private:int a;public:void seta( ) ;int geta( ) ;};void A: :seta( ){ a=1;}int A: :geta( ){ retum a;}class B{ private:int a;public:void seta( ) ;int geta( ) ;};void B: :seta( ){a=2;}int B: :geta( ){return a;}class C: public A,public B{ private:int b;public:void display( ) ;};void C: :display( ){ int b=geta( ) ;cout < < b;}void main( ){ C c;c. seta( ) ;c. display( ) ;}A.1B.2C.随机输出1或2D.程序有错

若有以下程序:includeusing namespace std;class A{private:int a; public:void seta 若有以下程序: #include<iostream> using namespace std; class A { private: int a; public: void seta(int x) { a=x; } void showa() { cout<<a<<","; } }; class B { private: int b; public: void setb(int x) { b=x; } void showb() { cout<<b<<",”; } }; class C:pUblic A,private B { private: int c; public: void setc(int x,int y,int z) { c=z; seta(x); setb(y); } void showc() { showa(); showb(); cout<<c<<end1; } }; int main() { Cc; c.setc(1,2,3); c.showc(); retrun 0; } 程序执行后的输出结果是A.1,2,3B.1,1,1C.2,2,2D.3,3,3

类class one 在声明func 成员函数时发生错误,出错原因是【 】。Class one{private:int a;public:void func(two )};class two{private:int b;friend void one: :func(two );};void one: : func(two r)a=r.b;}

以下语句能顺利通过编译: class class1 { private final void method1() {} }。() 此题为判断题(对,错)。

第六题 阅读下列说明和C++代码,填补代码中的空缺,将解答填入答题纸的对应栏内。【说明 】以下C++代码实现一个超市简单销售系统中的部分功能,顾客选择图书等物品(Item)加入购物车(ShoppingCart),到收银台(Cashier)对每个购物车中的物品统计其价格进行结账,设计如图6-1所示类图。using namespace std;class Book;class Visitor {public: virtual void visit(Book* book)=0; //其它物品的visit方法};class Item {public:virtual void accept(Visitor* visitor)=0; virtual double getPrice()=0;};class Book (1){private: double price;public: Book (double price){ //访问本元素 (2); } void accept(Visitor* visitor) { (3); } double getPrice() { return price; }};class Cashier(4){private; double totalForCart;public: //访问Book类型对象的价格并累加 (5){ //假设Book类型的物品价格超过10元打8折 if(book->getPrice() totalForCart+=book->getPrice(); } else totalForCart+=book->getPrice()*0.8; } //其它visit方法和折扣策略类似,此处略 double getTotal() { return totalForCart; }};class ShoppingCart {private: vectoritems;public: double calculatePrice() { Cashier* visitor=new Cashier(); for(int i=0;i (6); } double total=visitor->getTotal(); return total; } void add(Item*e) { items.push_back(e); }};

阅读下列说明和C++代码,填补代码中的空缺,将解答填入答题纸的对应栏内。【说明】以下C++代码实现一个超市简单销售系统中的部分功能,顾客选择图书等物品(Item)加入购物车(ShoppingCart),到收银台(Cashier)对每个购物车中的物品统计其价格进行结账,设计如图6-1所示类图。【C++代码】using namespace std;class Book;class Visitor {public: virtual void visit(Book* book)=0; //其它物品visit方法}; class Item {public:virtual void accept(Visitor* visitor)=0; virtual doublegetPrice()=0;};class Book (1){private: double price;public: Book (double price){ //访问本元素 (2); } void accept(Visitor* visitor) { (3); }double getPrice(){ returnprice; }};class Cashier(4){private; double totalForCart;public: //访问Book类型对象的价格并累加 (5){ //假设Book类型的物品价格超过10元打8折 if(book->getPrice()getPrice(); } else totalForCart+=book->getPrice()*0.8; } //其它visit方法和折扣策略类似,此处略 double getTotal() { return totalForCart; }};class ShoppingCart {private: vectoritems;public: double calculatePrice() { Cashier* visitor=new Cashier(); for(int i=0;i getTotal(); return total; } void add(Item*e) { items.push_back(e); }};

1. public class Target {  2. private int i = 0;  3. public int addOne() {  4. return ++i;  5. }  6. }  And:  1. public class Client {  2. public static void main(String[] args) {  3. System.out.println(new Target().addOne());  4. }  5. }  Which change can you make to Target without affecting Client?() A、 Line 4 of class Target can be changed to return i++;B、 Line 2 of class Target can be changed to private int i = 1;C、 Line 3 of class Target can be changed to private int addOne() {D、 Line 2 of class Target can be changed to private Integer i = 0;

1. public interface A {  2. public void doSomething(String thing);  3. }  1. public class AImpl implements A {  2. public void doSomething(String msg) { }  3. }  1. public class B {  2. public A doit() {  3. // more code here  4. }  5.  6. public String execute() { 7. // more code here  8. }  9. }  1. public class C extends B {  2. public AImpl doit() {  3. // more code here  4. }  5.  6. public Object execute() {  7. // more code here  8. }  9. }  Which statement is true about the classes and interfaces in the exhibit?() A、 Compilation will succeed for all classes and interfaces.B、 Compilation of class C will fail because of an error in line 2.C、 Compilation of class C will fail because of an error in line 6.D、 Compilation of class AImpl will fail because of an error in line 2.

Which declaration prevents creating a subclass of an outer class?()A、 Static class FooBar{}B、 Private class FooBar{}C、 Abstract public class FooBar{}D、 Final public class FooBar{}E、 Final abstract class FooBar{}

Given classes defined in two different files:  1. package util;  2. public class BitUtils {  3. private static void process(byte[] b) { }  4. }  1. package app;  2. public class SomeApp {  3. public static void main(String[] args) {  4. byte[] bytes = new byte[256];  5. // insert code here  6. }  7. }  What is required at line 5 in class SomeApp to use the process method of BitUtils?() A、 process(bytes);B、 BitUtils.process(bytes);C、 app.BitUtils.process(bytes);D、 util.BitUtils.process(bytes);E、 import util.BitUtils. *; process(bytes);F、 SomeApp cannot use the process method in BitUtils.

下列哪个类的声明是正确的()A、abstract final class HI{}B、abstract private move(){}C、protected private number;D、public abstract class Car{}

public class X {  public X aMethod() { return this;}  }  public class Y extends X {  }  Which two methods can be added to the definition of class Y?()A、 public void aMethod() {}B、 private void aMethod() {}C、 public void aMethod(String s) {}D、 private Y aMethod() { return null; }E、 public X aMethod() { return new Y(); }

class BaseClass{  private float x= 1.0f;  protected void setVar (float f) {x = f;}  }  class SubClass extends BaseClass   {  private float x = 2.0f;  //insert code here  }   Which two are valid examples of method overriding?()        A、 Void setVar(float f) {x = f;}B、 Public void setVar(int f) {x = f;}C、 Public void setVar(float f) {x = f;}D、 Public double setVar(float f) {x = f;}E、 Public final void setVar(float f) {x = f;}F、 Protected float setVar() {x=3.0f; return 3.0f; }

单选题Which declaration prevents creating a subclass of an outer class?()A Static class FooBar{}B Private class FooBar{}C Abstract public class FooBar{}D Final public class FooBar{}E Final abstract class FooBar{}

单选题下列哪个类的声明是正确的()Aabstract final class HI{}Babstract private move(){}Cprotected private number;Dpublic abstract class Car{}

多选题public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()Apublic class Circle implements Shape { private int radius; }Bpublic abstract class Circle extends Shape { private int radius; }Cpublic class Circle extends Shape { private int radius; public void draw(); }Dpublic abstract class Circle implements Shape { private int radius; public void draw(); }Epublic class Circle extends Shape { private int radius;public void draw() {/* code here */} }Fpublic abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }

单选题Given classes defined in two different files:  1. package util;  2. public class BitUtils {  3. private static void process(byte[] b) { }  4. }  1. package app;  2. public class SomeApp {  3. public static void main(String[] args) {  4. byte[] bytes = new byte[256];  5. // insert code here  6. }  7. }  What is required at line 5 in class SomeApp to use the process method of BitUtils?()A process(bytes);B BitUtils.process(bytes);C app.BitUtils.process(bytes);D util.BitUtils.process(bytes);E import util.BitUtils. *; process(bytes);F SomeApp cannot use the process method in BitUtils.

单选题下列哪个类声明是正确的()。Aabstract final class H1{…}Babstract private move(){…}Cprotected private number;Dpublic abstract class Car{…}

多选题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? ()Adeclare reset() using the synchronized keywordBdeclare getName() using the synchronized keywordCdeclare getCount() using the synchronized keywordDdeclare the constructor using the synchronized keywordEdeclare increment() using the synchronized keyword

单选题现有:  1. interface Animal {  2. void eat();  3. }  4.  5. // insert code here  6.  7. public class HouseCat extends Feline {  8. public void eat() { }  9. }   和五个声明:  abstract class Feline implements Animal { }  abstract class Feline implements Animal { void eat(); }  abstract class Feline implements Animal { public void eat(); }  abstract class Feline implements Animal { public void eat() { } }  abstract class Feline implements Animal { abstract public void eat(); }  分别插入到第5行,有几个可以通过编译?()A0B1C2D3

单选题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);  } }  结果为:()Aelm elm elm elmBtree elm elm elmCtree elm tree elmD编译失败

多选题class BaseClass{  private float x= 1.0f;  protected void setVar (float f) {x = f;}  }  class SubClass extends BaseClass   {  private float x = 2.0f;  //insert code here  }   Which two are valid examples of method overriding?()AVoid setVar(float f) {x = f;}BPublic void setVar(int f) {x = f;}CPublic void setVar(float f) {x = f;}DPublic double setVar(float f) {x = f;}EPublic final void setVar(float f) {x = f;}FProtected float setVar() {x=3.0f; return 3.0f; }

多选题class BaseClass{   private float x= 1.0f;   protected void setVar (float f) {x = f;}   }   class SubClass exyends BaseClass {   private float x = 2.0f;   //insert code here  8. }   Which two are valid examples of method overriding?()AVoid setVar(float f) {x = f;}BPublic void setVar(int f) {x = f;}CPublic void setVar(float f) {x = f;}DPublic double setVar(float f) {x = f;}EPublic final void setVar(float f) {x = f;}FProtected float setVar() {x=3.0f; return 3.0f; }

多选题现有:  public  class  TestDemo{     private int X-2;      static int y=3;  public  void method(){      final int i=100;      int j  =10;     class Cinner {  public void mymethod(){      //Here     }     }     }     } 在Here处可以访问的变量是哪些?()AXByCjDi

多选题public class TestDemo{   private int x = 2;   static int y = 3;   public void method(){   final int i=100;   int j = 10;   class Cinner{   public void mymethod(){  //Here  }  }  }  }   在Here处可以访问的变量是哪些?()AxByCiDj