多选题public class OuterClass {  private double d1  1.0;  //insert code here   }   You need to insert an inner class declaration at line2. Which two inner class declarations are valid?()Astatic class InnerOne {  public double methoda() {return d1;}  }Bstatic

题目
多选题
public class OuterClass {  private double d1  1.0;  //insert code here   }   You need to insert an inner class declaration at line2. Which two inner class declarations are valid?()
A

static class InnerOne {  public double methoda() {return d1;}  }

B

static class InnerOne {  static double methoda() {return d1;} }

C

private class InnerOne {  public double methoda() {return d1;} }

D

protected class InnerOne {  static double methoda() {return d1;} }

E

public abstract class InnerOne {  public abstract double methoda();  }


相似考题

1.阅读下列Java程序和程序说明,将应填入(n)处的字句写在对应栏内。【说明】下面的程序先构造Point类,再顺序构造Ball类。由于在类Ball中不能直接存取类Point中的xCoordinate及yCoordinate属性值,Ball中的toString方法调用Point类中的toString方法输出中心点的值。在MovingBall类的toString方法中,super.toString调用父类Ball的toString方法输出类Ball中声明的属性值。public class Point{private double xCoordinate;private double yCoordinate;public Point 0 }public Point(ouble x, double y){xCoordinate = x;yCoordinate = y;}public String toString(){return "( + Double.toString(Coordinate)+ ","+ Double.toString(Coordinate) + ");}//other methods}public class Ball{(1); //中心点private double radius; //半径private String colour; ///颜色public Ball() { }public Ball(double xValue, double yValue, double r)// 具有中心点及半径的构造方法{center=(2);//调用类Point 中的构造方法radius = r;}public Ball(double xValue, double yValue, double r, String c)// 具有中心点、半径及颜色的构造方法{(3);//调用3个参数的构造方法colour = c;}public String toString(){return "A ball with center" + center, toString() + ", radius"+ Double.toString(radius) + ", colour" + colour;}//other methods}public class MovingBall. (4){private double speed;public MovingBall() { }public MovingBall(double xValue, double yValue, double r, String e, double s){(5);// 调用父类Ball中具有4个参数的构造方法speed = s;}public String toString( ){ return super, toString( ) + ", speed "+ Double.toString(speed); }//other methods}public class Tester{public static void main(String args[]){MovingBall mb = new MovingBall(10,20,40,"green",25);System.out.println(mb);}}

参考答案和解析
正确答案: B,D
解析: 暂无解析
更多“public class OuterClass {  private double d1  1.0;  //insert”相关问题
  • 第1题:

    Given:Which two methods, inserted independently at line 17, correctly complete the Sales class?()

    A.double getSalesAmount() { return 1230.45; }

    B.public double getSalesAmount() { return 1230.45; }

    C.private double getSalesAmount() { return 1230.45; }

    D.protected double getSalesAmount() { return 1230.45; }


    参考答案:B, D

  • 第2题:

    下列程序的执行结果为【 】。include class Point{public:Point(double i, double j)

    下列程序的执行结果为【 】。

    include <iostream. h>

    class Point

    {

    public:

    Point(double i, double j) { x=i; y=j;}

    double Area() const { return 0.0;}

    private:

    double x, y;

    };

    class Rectangle: public Point

    {

    public:

    Rectangle(double i, double j, double k, double 1)

    double Area() const {return w * h;}

    private:

    double w, h;

    };

    Rectangle: :Rectangle(double i, double j, double k. double 1): Point(i,j).

    {

    w=k, h=1

    }

    void fun(Point &s)

    {

    cout<<s. Area()<<end1;

    }

    void main( )

    {

    Rectangle rec(3.0, 5.2, 15.0. 25.0);

    fun(rec)

    }


    正确答案:×
    0 解析:注意本题不同于基类的指针指向派生类对象。Fun函数的形参是Point基类的引用。在可以用基类对象的地方,均可以用派生类替代,完成基类的行为。反之,在使用派生类对象的地方却不能用基类对象代替,这是因为派生类中的某些行为在基类对象中是不存在的。本题调用的是Point类对象的面积函数,其值永远为0。

  • 第3题:

    下列成员变量声明中,正确的是______。

    A.public protected final int i;

    B.abstract class F1{…}

    C.private double height;

    D.double weight


    正确答案:C
    解析: 成员变量的修饰符可以是public、protected、private、static、final、transient、volatile等,选项A错误。成员变量不能同时声明成public和protected。选项B是类的声明格式,并不是成员变量的声明。成员变量声明应以“;”结束,选项D不正确。选项C声明一个私有的double型成员变量,此为正确答案。

  • 第4题:

    下列选项成员变量声明正确的是( )。

    A.public protected final int i;

    B.abstract class Fl{…}

    C.private double height;

    D.double weight


    正确答案:C
    C。【解析】本题考查对成员变量的声明。成员变量的声明格式为:修饰符type变量名;其中type可以是java语言中的任意数据类型,而修饰符可以是public、protected,private,static,final,transient,volatile等。选项A错误,成员变量不能同时声明成public和protected。选项B是类的声明格式,并不是成员变量的声明。成员变量声明应以";"结尾,选项D错误。选项C声明了一个私有的double型成员变量,为正确答案。

  • 第5题:

    有如下两个类定义: class XX{ private: double xl; protected: double x2; public: double x3; }; class YY:protected XX{ private: double yl; protected: double y2; public: double y3; 在类YY中保护成员变量的个数是( )。

    A.1

    B.2

    C.3

    D.4


    正确答案:C
    本题考查保护继承中派生类对基类的访问属性,在受保护继承中,基类的公用成员和保护成员在派生类中成了保护成员,所以基类的成员x2、x3变成了保护成员,派生类中的y2也是保护成员,所以共有3个保护成员。本题答案为C、

  • 第6题:

    1. class BaseClass {  2. private float x = 1.of;  3. protected float getVar() { return x; }  4. }  5. class SubClass extends BaseClass {  6. private float x = 2.Of;  7. // insert code here 8. }   Which two are valid examples of method overriding when inserted at line 7?() 

    • A、 float getVar() { return x; }
    • B、 public float getVar() { return x; }
    • C、 public double getVar() { return x; }
    • D、 protected float getVar() { return x; }
    • E、 public float getVar(float f) { return f; }

    正确答案:B,D

  • 第7题:

    Which three demonstrate an “is a” relationship?() 

    • A、 public class X {  }     public class Y extends X { }
    • B、 public interface Shape { }     public interface Rectangle extends Shape{ }
    • C、 public interface Color { }     public class Shape { private Color color; }
    • D、 public interface Species { }     public class Animal { private Species species; }
    • E、 public class Person { }    public class Employee {      public Employee(Person person) { }
    • F、 interface Component { }     class Container implements Component {   private Component[] children; }

    正确答案:A,B,F

  • 第8题:

    public class OuterClass {  private double d1  1.0;  //insert code here   }   You need to insert an inner class declaration at line2. Which two inner class declarations are valid?() 

    • A、 static class InnerOne {  public double methoda() {return d1;}  }
    • B、 static class InnerOne {  static double methoda() {return d1;} }
    • C、 private class InnerOne {  public double methoda() {return d1;} }
    • D、 protected class InnerOne {  static double methoda() {return d1;} }
    • E、 public abstract class InnerOne {  public abstract double methoda();  }

    正确答案:C,E

  • 第9题:

    Which the two demonstrate an “is a” relationship?()

    • A、 public interface Person {}  Public class Employee extends Person {}
    • B、 public interface Shape {}  public interface Rectangle extends Shape {}
    • C、 public interface Color {}  public class Shape { private Color color; }
    • D、 public class Species {}  public class Animal { private Species species; }
    • E、 interface Component {} Class Container implements Component {private Component [] children;

    正确答案:B,E

  • 第10题:

    public class Car {  private int wheelCount;  private String vin;  public Car(String vin) {  this.vin = vin;  this.wheelCount = 4;  }  public String drive() {  return “zoom-zoom”;  }  public String getInfo() {  return “VIN: “+ vin + “wheels: “+ wheelCount;  }  }  And:  public class MeGo extends Car {  public MeGo(String vin) {  this.wheelCount = 3;  }  }  What two must the programmer do to correct the compilation errors?()

    • A、 insert a call to this() in the Car constructor
    • B、 insert a call to this() in the MeGo constructor
    • C、 insert a call to super() in the MeGo constructor
    • D、 insert a call to super(vin) in the MeGo constructor
    • E、 change the wheelCount variable in Car to protected
    • F、 change line 3 in the MeGo class to super.wheelCount = 3;

    正确答案:D,E

  • 第11题:

    单选题
    Which will declare a method that is available to all members of the same package and can be referenced without an instance of the class?()
    A

     Abstract public void methoda();

    B

     Public abstract double methoda();

    C

     Static void methoda(double d1){}

    D

     Public native double methoda()  {}

    E

     Protected void methoda(double d1)  {}


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

  • 第12题:

    多选题
    public class OuterClass {   private double d1 1.0;   //insert code here   }   You need to insert an inner class declaration at line2. Which two inner class declarations are valid?()
    A

    static class InnerOne {  public double methoda() {return d1;}  }

    B

    static class InnerOne {  static double methoda() {return d1;}  }

    C

    private class InnerOne {  public double methoda() {return d1;}  }

    D

    protected class InnerOne {  static double methoda() {return d1;}  }

    E

    public abstract class InnerOne {  public abstract double methoda();  }


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

  • 第13题:

    阅读以下函数说明和Java代码,将应填入(n)处的字句写在对应栏内。

    【说明】

    下面的程序先构造Point类,再顺序构造Ball类。由于在类Ball中不能直接存取类Point中的xCoordinate及yCoordinate属性值,Ball中的toString方法调用Point类中的toStrinS方法输出中心点的值。在MovingBsll类的toString方法中,super.toString调用父类Ball的toString方法输出类Ball中声明的属性值。

    【Java代码】

    //Point.java文件

    public class Point{

    private double xCoordinate;

    private double yCoordinate;

    public Point(){}

    public Point(double x,double y){

    xCoordinate=x;

    yCoordinate=y;

    }

    public String toStrthg(){

    return"("+Double.toString(xCoordinate)+","

    +Double.toString(yCoordinate)+")";

    }

    //other methods

    }

    //Ball.java文件

    public class Ball{

    private (1);//中心点

    private double radius;//半径

    private String color;//颜色

    public Ball(){}

    public Ball(double xValue, double yValue, double r){

    //具有中心点及其半径的构造方法

    center=(2);//调用类Point中的构造方法

    radius=r;

    }

    public Ball(double xValue, double yValue, double r, String c){

    //具有中心点、半径和颜色的构造方法

    (3);//调用3个参数的构造方法

    color=c;

    }

    public String toString(){

    return "A ball with center"+center.toString()

    +",radius "+Double.toString(radius)+",color"+color;

    }

    //other methods

    }

    class MovingBall (4) {

    private double speed;

    public MovingBall(){}

    public MoyingBall(double xValue, double yValue, double r, String c, double s){

    (5);//调用父类Ball中具有4个参数的构造方法

    speed=s;

    }

    public String toString(){

    return super.toString()+",speed"+Double.toString(speed);

    }

    //other methods

    }

    public class test{

    public static void main(String args[]){

    MovingBall mb=new MovingBall(10,20,40,"green",25);

    System.out.println(mb);

    }

    }


    正确答案:(1) Point center (2) new Point(xValueyValue) (3) this(xValueyValuer) (4) extends Ball (5) super(xValueyValuerc)
    (1) Point center (2) new Point(xValue,yValue) (3) this(xValue,yValue,r) (4) extends Ball (5) super(xValue,yValue,r,c) 解析:在类Ball的有参数构造函数中,对成员变量center通过调用Point类的构造方法初始化,而center在类Ball中尚未声明。结合注释可得空(1)是将center变量声明为Point对象引用,故空(1)应填Point。空(2)是调用Point类的构造函数,根据题意,此处应将xValue和yValue作为参数调用类Point的有参数构造函数,故空(2)应填new Point(xValue,yValue)。
    根据注释,空(3)是调用类Ball的有3个参数的构造方法,而其所在方法本身就是类Ball的一个构造方法,因此可用this来调用自身的构造方法,故空(3)应填this(xValue,yValue,r)。
    根据题述“在MovingBall类的toString方法中,super.toString调用父类Ball的toString方法输出类Ball中声明的属性值”,可知类MovingBall是类Ball的子类,因此空(4)应填extends Ball。
    根据注释,空(5)是调用父类Ball中具有4个参数的构造方法,通过super关键字实现,故空(5)应填super(xValue,yValue,r,c)。

  • 第14题:

    下列选项成员变量声明正确的是

    A.public protected final int i;

    B.abstract class F1{…}

    C.private double height;

    D.double weight{}


    正确答案:C
    解析:本题考查对成员变量的声明。成员变量的声明格式位:修饰符type变量名;其中type可以是java语言中的任意数据类型,而修饰符可以是public、protected, private,static,final,transient,volatile等。选项A错误,成员变量不能同时声明成 public和protected。选项B是类的声明格式,并不是成员变量的声明。成员变量声明应以“;”结尾,选项D错误。选项C声明了一个私有的double型成员变量,为正确答案。

  • 第15题:

    有以下程序:includeusing namespace std;class sample{private:int x;public:sample(

    有以下程序: #include<iostream> using namespace std; class sample { private: int x; public: sample(int A) { x=a; friend double square(sample s); }; double square(sample s) { return S.X*S.K; } int main() { sa

    A.20

    B.30

    C.900

    D.400


    正确答案:C
    解析: 本题考查友元函数的应用。程序中函数square是类sample的一个友元函数,它可以直接访问类sam- pie的所有成员。它的功能是返回类sample的私有数据成员x的平方。所以程序的执行结果是900。

  • 第16题:

    有以下程序:includeincludeusing namespace std; class point{private:double

    有以下程序: #include<iostream> #include<math> using namespace std; class point { private: double x; double y; public: point(double a,double B) { x=a; y=b; } friend double distance (point a,point B) ;

    A.1

    B.5

    C.4

    D.6


    正确答案:C
    解析:本题考核友元函数的应用。分析程序:类point中定义了两个私有成员x和y,以及一个友元函数distance。从而,函数distance可以访问类point中的任何成员。在函数distance中,返回值为sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))。由此可知,函数distance的功能是计算a、b两点之间的距离。在主函数main中,先定义两点:p1(1,2)和p2(5,2)。然后调用函数distance计算两点之间的距离为4,所以程序最后输出为4。

  • 第17题:

    阅读下列说明和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
    【说明】
    某大型购物中心欲开发一套收银软件,要求其能够支持购物中心在不同时期推出的各种促销活动,如打折、返利(例如,满300返100)等等。现采用策略(Strategy)模式实现该要求,得到如图6-1所示的类图。



    import javA.util.*;
    enum TYPE {
    NORMAL, CASH_DISCOUNT, CASH_RETURN};
    interface
    CashSuper {

    public (1) ;
    }
    class CashNormal
    implements CashSuper{ // 正常收费子类

    public double accptCash(double money){

    return money;
    }
    }
    class
    CashDiscount implements CashSuper {

    private double moneyDiscount;
    // 折扣率

    public CashDiscount(double moneyDiscount) {

    this moneyDiscount = moneyDiscount;
    }

    public double acceptCash(double money) {

    return money* moneyDiscount;
    }
    }
    class CashReturn
    implements CashSuper { // 满额返利

    private double moneyCondition;

    private double moneyReturn;

    public CashReturn(double moneyCondition, double moneyReturn) {


    this.moneyCondition =moneyCondition; // 满额数额

    this.moneyReturn =moneyReturn; // 返利数额
    }

    public double acceptCash(double money) {

    double result = money;

    if(money >= moneyCondition )

    result=money-Math.floor(money/moneyCondition ) *
    moneyReturn;

    return result;
    }
    }
    class
    CashContext_{

    private CashSuper cs;

    private TYPE t;

    public CashContext(TYPE t) {

    switch(t){

    case NORMAL: // 正常收费

    (2) ;

    break;

    case CASH_DISCOUNT: // 满300返100

    (3) ;

    break;

    case CASH_RETURN: // 打8折

    (4) ;

    break;

    }
    }

    public double GetResult(double money) {

    (5) ;
    }
    ∥此处略去main( )函数
    }


    答案:
    解析:
    (1)double acceptCash(double money) (2)cs = new CashNormal()(3)cs = new CashDiscount(0.8)(4)cs = new CashReturn(300,100)(5)return cs.acceptCash(money)

  • 第18题:

    Which will declare a method that is available to all members of the same package and can be referenced  without an instance of the class?()  

    • A、 Abstract public void methoda();
    • B、 Public abstract double methoda();
    • C、 Static void methoda(double d1){}
    • D、 Public native double methoda(){}
    • E、 Protected void methoda(double d1){}

    正确答案:C

  • 第19题:

    10. abstract public class Employee {  11. protected abstract double getSalesAmount();  12. public double getCommision() {  13. return getSalesAmount() * 0.15;  14. }  15. }  16. class Sales extends Employee {  17. // insert method here  18. }  Which two methods, inserted independently at line 17, correctly complete the Sales class?()

    • A、 double getSalesAmount() { return 1230.45; }
    • B、 public double getSalesAmount() { return 1230.45; }
    • C、 private double getSalesAmount() { return 1230.45; }
    • D、 protected double getSalesAmount() { return 1230.45; }

    正确答案:B,D

  • 第20题:

    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; }

    正确答案:C,E

  • 第21题:

    1. public class OuterClass {  2. private double d1 = 1.0;  3. // insert code here  4. }  Which two are valid if inserted at line 3?()  

    • A、 static class InnerOne { public double methoda() { return d1; } }
    • B、 static class InnerOne { static double methoda() { return d1; } }
    • C、 private class InnerOne { public double methoda() { return d1; } }
    • D、 protected class InnerOne { static double methoda() { return d1; } }
    • E、 public abstract class InnerOne { public abstract double methoda(); }

    正确答案:C,E

  • 第22题:

    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?()

    • A、 public class Circle implements Shape { private int radius; }
    • B、 public abstract class Circle extends Shape { private int radius; }
    • C、 public class Circle extends Shape { private int radius; public void draw(); }
    • D、 public abstract class Circle implements Shape { private int radius; public void draw(); }
    • E、 public class Circle extends Shape { private int radius;public void draw() {/* code here */} }
    • F、 public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }

    正确答案:B,E

  • 第23题:

    多选题
    1. public class OuterClass {  2. private double d1 = 1.0;  3. // insert code here  4. }  Which two are valid if inserted at line 3?()
    A

    static class InnerOne { public double methoda() { return d1; } }

    B

    static class InnerOne { static double methoda() { return d1; } }

    C

    private class InnerOne { public double methoda() { return d1; } }

    D

    protected class InnerOne { static double methoda() { return d1; } }

    E

    public abstract class InnerOne { public abstract double methoda(); }


    正确答案: C,A
    解析: 暂无解析

  • 第24题:

    多选题
    10. abstract public class Employee {  11. protected abstract double getSalesAmount();  12. public double getCommision() {  13. return getSalesAmount() * 0.15;  14. }  15. }  16. class Sales extends Employee {  17. // insert method here  18. }  Which two methods, inserted independently at line 17, correctly complete the Sales class?()
    A

    double getSalesAmount() { return 1230.45; }

    B

    public double getSalesAmount() { return 1230.45; }

    C

    private double getSalesAmount() { return 1230.45; }

    D

    protected double getSalesAmount() { return 1230.45; }


    正确答案: A,B
    解析: 暂无解析