static class InnerOne { public double methoda() {return d1;} }
static class InnerOne { static double methoda() {return d1;} }
private class InnerOne { public double methoda() {return d1;} }
protected class InnerOne { static double methoda() {return d1;} }
public abstract class InnerOne { public abstract double methoda(); }
第1题:
阅读下列代码 public class { public static void main(String args[]){ double d=12.3; Decrementer dec=new Decrementer(); dec. decrement(D) ; System. out. println(D) ; } } class Decrementer{ public void decrement(double decMe){ decMe=decMe-1.0; } } 代码执行后输出结果是
A.12.3
B.11.3
C.13.3
D.-1.0
第2题:
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; }
第3题:
阅读下列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);
}
}
第4题:
下列成员变量声明中,正确的是______。
A.public protected final int i;
B.abstract class F1{…}
C.private double height;
D.double weight
第5题:
下列程序的执行结果为【 】。
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)
}
第6题:
有如下两个类定义: class XX{ private: double X1; protected: double x2; public: doublex3; ); clase YY:protected XX{ private: doubley1; protected: doubley2; public: double y3; }; 在类YY中保护成员变量的个数是( )。
A.1
B.2
C.3
D.4
第7题:
阅读以下函数说明和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);
}
}
第8题:
( 23 )有如下两个类定义
class XX{
private:
double x1;
protected:
double x2;
public:
double x3;
};
class YY:protected XX{
private:
double y1;
protected:
double y2;
public:
double y3;
};
在类 YY 中保护成员变量的个数是
A ) 1
B ) 2
C ) 3
D ) 4
第9题:
下列选项成员变量声明正确的是
A.public protected final int i;
B.abstract class F1{…}
C.private double height;
D.double weight{}
第10题:
有以下程序: #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