已知有下面的类说明: pubic class Test4 { private float f=0f; int m=12; static int n=1; public static void main(String args[]) { Test4 e=new Test4(); } } 在main()方法中,下面( )使用是正确的。A.e.fB.this.nC.Test4.mD.Test4.f

题目

已知有下面的类说明: pubic class Test4 { private float f=0f; int m=12; static int n=1; public static void main(String args[]) { Test4 e=new Test4(); } } 在main()方法中,下面( )使用是正确的。

A.e.f

B.this.n

C.Test4.m

D.Test4.f


相似考题
更多“已知有下面的类说明:pubic class Test4{private float f=0f;int m=12;static int n=1;public sta ”相关问题
  • 第1题:

    已知如下类说明: public class Test { private float f = 1.0f; int m = 12; static int n=1; public static void main(String arg[]) { Test t = new Test(); // 程序代码… } } 如下哪个使用是正确的?()

    A.t.f

    B.this.n

    C.Test.m

    D.Test.n


    正确答案:AD

  • 第2题:

    类Test定义如下,将下列______方法插入③行处是不合法的。 ( )①public class Test{②public float Method(float a,float b){}③④}

    A.public float Method(float a,float b,float c){}

    B.public float Method(float c,float d){}

    C.public int Method(int a,int b){}

    D.private float Method(int a,int b,int c){}


    正确答案:B
    解析:该题考查的方法重载。在 Java程序中可以在同一个类中定义多个名称相同的方法,然而这些方法的参数数量和类型却不完全相同,这种现象被成为方法重载。在本题中,选项A是正确的,虽然它的参数的类型和第二行的参数类型相同,但是它的参数数量是不同的;选项B不正确,它的参数类型和参数数量都和第二行的相同;选项C正确,它的参数类型和第二行的参数类型不同;选项D也正确,它的参数类型和数量都不和第二行的相同。

  • 第3题:

    已知有下列类的说明,则下列哪个语句是正确的?public class Test { private float f=1.0f; int m=12; static int n=1; public static void main(String arg[]) { Test t= new Test(); }}

    A.t.f;

    B.this. n

    C.Test.m;

    D.Test.f;


    正确答案:A
    解析:此题主要考查对象的正确使用,其格式为对象名.调用的方法名或变量名。在static方法中,不能使用 this。变量m和f都不是静态成员,所以不能用类名.成员方式访问。

  • 第4题:

    下面代码的执行结果是( )。 public class test { public static void main (String args[]) { float m=5.0f; int n=4; System.out.println((++m)*(n--)); } }

    A.20.0

    B.20

    C.24.0

    D.24


    正确答案:C
    解析:本题考查自增(自减)运算和类型的自动转换。由于++m表达式中++在变量之前,所以先对m进行自增运算,将m加上1.0,再将m的值作为表达式++m的值,即(++m)的值是 6.0;而在n--表达式中,--在变量n之后,所以先取变量n的值作为表达式的值,变量n再自减,即 (n--)的值是4,然后作6.0*4运算,此时整数4会自动转换为实型数据再参与运算,所以结果是24.0而不是24。故选C。

  • 第5题:

    阅读下面程序 public class Test4 { public static void main(String[] args) { int 1=10,j=3; float m=213.5f,n=4.0f; System.out.println(i%j); System.out.println(m%n); } } 程序运行的结果是

    A.1.0和1.5

    B.1和1.5

    C.1.0和2.5

    D.1和2.5


    正确答案:B
    解析:对二元运算,如果操作数全为整型,那么只要其中有一个为long型,则表达式结果也为long型;其他情况下,即使两个操作数全是byte型或short型,表达式结果也为int型;如果操作数为浮点型,那么只要其中有一个为double型,表达式结果就是double型;只有两个操作数全是float型或其中一个是float型而另外一个是整型时,表达式结果才是float型。因而第一次输出的结果是整型的1,第二次输出的结果是float型的1.5。

  • 第6题:

    下列代码执行结果为 ( )public class Test{ public static void main(String args[]){ float p=0f; int q=3; System.out.println(++p)*(q--)); }}

    A.16

    B.24

    C.16

    D.24


    正确答案:D
    解析:该题考查的是简单的运算。 i++是i先运算,后i+1;而++i则是先i+1,后运算。—操作符和++操作符用法相同;不同类型数进行运算时的转换,在运算时遵循这样一个转换规则byte→short→int→long→float→ double和char→int。本题中,参与运算的数是 8.0*3,结果是24.0,所以选D。

  • 第7题:

    类testl定义如下: public class test1 { public float amethod(float a,float b){ } }

    A.public foat amethod(float a,float b,foat c){ }

    B.public float amethod(float c,float d){ }

    C.public int amethod(int a,int b){ }

    D.private float amethod(int a,int b,int c){ }


    正确答案:B

  • 第8题:

    已知有下列类的说明,则下列哪个语句是正确的? ( ) public class Test { private float f=1.0f; int m=2; static int n=1; public static void main(String arg[]) { Test t=new Test(); } }

    A.t.f;

    B.this,n;

    C.Test.m;

    D.Test.f;


    正确答案:A

  • 第9题:

    有下列程序:includeusing namespace Std;class Test{public:Test(){n+=2;}~Test(){n-

    有下列程序: #include<iostream> using namespace Std; class Test { public: Test() {n+=2;} ~Test() {n-=3;} static int getNum(){return n;} private: static int n; }; int Test∷n=1; int main()

    A.n=0

    B.n=l

    C.n=2

    D.n=3


    正确答案:A
    解析: 此题考查的是静态数据成员和静态成员函数。静态数据成员是类中所有对象共享的成员,而不是某个对象的成员。题目中的静态数据成员n的运算具有叠加性,执行“n+=2”和“n-=3”后n的值为0。

  • 第10题:

    类中包含了一个静态成员函数,则main函数中和P.f1(P);语句具有同样功能的语句为______。

    include<iostream.h>

    class M

    {public:

    M(int A){A=a;B+=a;}

    static void f1(M m);

    private:

    int A;

    static int B;};

    void M::f1(M m)

    {

    cout<<“A=“<<m.A((end1;

    cout<<“B=”<<m.B<<en


    正确答案:M::f1(P);。
    M::f1(P);。 解析: 由于f1是类M的静态成员函数,即说明类M的任何对象都共享一份f1,因此,不仅可以从对象那里访问f1,还可以用域操作符::通过类名来访问。

  • 第11题:

    public class MethodOver {   public void setVar (int a, int b, float c) {   }   }   Which two overload the setVar method?()

    • A、 Private void setVar (int a, float c, int b) {}
    • B、 Protected void setVar (int a, int b, float c) {}
    • C、 Public int setVar (int a, float c, int b) (return a;)
    • D、 Public int setVar (int a, int b, float c) (return a;)
    • E、 Protected float setVar (int a, int b, float c) (return c;)

    正确答案:A,C

  • 第12题:

    public class MethodOver {   private int x, y;   private float z;   public void setVar(int a, int b, float c){   x = a;   y = b;   z = c;   }   }   Which two overload the setVar method?()

    • A、 void setVar (int a, int b, float c){  x = a;  y = b;  z = c;  }
    • B、 public void setVar(int a, float c, int b) {  setVar(a, b, c);  }
    • C、 public void setVar(int a, float c, int b) {  this(a, b, c);  }
    • D、 public void setVar(int a, float b){  x = a;  z = b;  }
    • E、 public void setVar(int ax, int by, float cz) {  x = ax;  y = by;  z = cz;  }

    正确答案:B,D

  • 第13题:

    给出下列代码,如何使成员变量m被方法fun( )直接访问?Class Test{private int m;public static void fun( ){} }

    A.将private int m改为protected int m

    B.将private int m改为public int m

    C.将private int m改为static int m

    D.将private int m改为int m


    正确答案:C

  • 第14题:

    给出下列代码,如何使成员变量m被方法fun( )直接访问? class Test{ private int m; public static void fun( ){ … } }

    A.将private int m改为protected int m

    B.将private int m改为public int m

    C.将private int m改为static i

    D.将private int m改为int m


    正确答案:C
    解析:在静态方法中不能直接访问非静态的成员,如果要在fun()中直接访问变量m,应将变量m用static修饰。

  • 第15题:

    已知有下列类的说明,则下列( )语句是正确的。 publicClass Test{ private float f=1.0f; int m=12; static int n=1: public static void main(Stringarg[]){ Test t=new Test(): } }

    A.t.f;

    B.this.n;

    C.Test.m;

    D.Test.f;


    正确答案:A

  • 第16题:

    已知有下面的类说明: public class Test4 { private float f=1.0f; int m=12; static int n=1; public static void main(String args[]) { Test4 e=new Test4(); } } 在main()方法中,下面哪个的使用是正确的? ( )

    A.e.f

    B.this.n

    C.Test4.m

    D.Test4.f


    正确答案:A
    解析:该题考查的是怎样引用对象的变量。访问对象成员变量的格式为:对象名.成员变量名。在本题中使用Test4e=newTest4();语句生成了对象并由变量e引用后,可以通过上述格式访问对象的成员f,即e.f。所以本题选A。

  • 第17题:

    下列程序的执行结果是【 】。 include < iostream. h> class Myclass { public: void GetSum(int a)

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

    include < iostream. h>

    class Myclass

    {

    public:

    void GetSum(int a)

    static int Sum:

    private:

    int A;

    };

    int Myclass:: Sum =10; //必须在类外部对静态数据成员初始化

    void Myelass: :GetSum(int a)

    {

    A=a;

    Sum+=A;

    }

    void PrintSum(Myclass& A)

    {

    cout<<"Sum="<<A.Sum<<end1;

    }

    void main( )

    {

    Myclass M,N;

    M. GetSum(3)

    N. GetSum(7)

    PrintSum(M);

    }


    正确答案:sum=20
    sum=20 解析:本题考察静态数据成员在同类的不同对象间的数据传递功能。Sum为所有对象的公共数据,M对象和N对象分别对sum进行累加,故结果为20。

  • 第18题:

    下列代码的执行结果是( )。 public class Test1 { public static void main(String args[]) float t = 0f; int q = 5; System.out.println((t++)*(--q)); }

    A.40

    B.40

    C.36

    D.36


    正确答案:D
    解析:本题考查++和--运算符,表达式(t++)*(--q)的结果为36.0。

  • 第19题:

    以下程序的执行结果是______。 include class CSample{ private: int n; static int

    以下程序的执行结果是______。

    include<iostream.h>

    class CSample

    {

    private:

    int n;

    static int k:

    public:

    CSample (int i) {n=i;k++;};

    voiddisp();

    } ;

    void CSample::disp()

    {

    cout <<"n="<<n<<",k="<<k<<endl

    }

    int CSample:


    正确答案:n=10k=3 n-20k=3 n=30k=3
    n=10,k=3 n-20,k=3 n=30,k=3

  • 第20题:

    类Test定义如下,将下列哪个方法插入③行处是不合法的( )?

    ① public class Test{

    ② public float Method(float a,float B) { }

    ③ ______

    ④ }

    A.public float Method(float a,float b,float C) { }

    B.public float Method(float c,float d){ }

    C.public int Method(int a,int B) { }private float Method(int a,int b,int C) { }

    D.private float Method(int a,int b,int C) { }


    正确答案:B
    解析:本题主要考查方法重载,方法的重载是指多个方法可以享有相同的名字,但参数的数量或类型必须不相同(采用不同的形式参数列表),选项B不符合方法重载的要求。

  • 第21题:

    已知有下列类的说明,则下列哪个语句是正确的? public class Test{ private float f = 1.0f; int m = 12; static int n=1; public static void main(String arg[ ]){ Test t = new Test( ); } }

    A.t.f;

    B.this.n;

    C.Test.m;

    D.Test.f;


    正确答案:A
    解析:此题主要考查对象的正确使用,其格式为对象名.调用的方法名或变量名。在static方法中,不能使用this。变量m和f都不是静态成员,所以不能用类名.成员方式访问。

  • 第22题:

    对于下面定义的类MyClass,请在函数f( )中添加对象成员把n的值修改为50。

    class MyClass

    {

    public:

    MyClass(int x){n=x;}

    void SetNum(int n1){n=n1;}

    private:

    int n;

    };

    void f()

    {

    My Class*ptr=new MyClass(45);

    【12】

    }


    正确答案:
    ptr->SetNum(50);

  • 第23题:

    类Test1定义如下: 1.public class Test1{ 2. public float aMethod(float a,float b){ return 0;} 3. 4.} 将以下哪种方法插入行3是不合法的。()

    • A、public float aMethod(float a, float b,float c){ return 0;}
    • B、public float aMethod(float c,float d){ return 0;}
    • C、public int aMethod(int a, int b){ return 0;}
    • D、private float aMethod(int a,int b,int c){ return 0;}

    正确答案:B