public static const int A=1;这段代码有错误么?是什么?

题目

public static const int A=1;这段代码有错误么?是什么?


相似考题
更多“public static const int A=1;这段代码有错误么?是什么?”相关问题
  • 第1题:

    下面代码段的输出结果为( )。 public class Test { public static void main(String sss[]) { int i=0xFFFFFFFl; int j=~i; } }

    A.0

    B.1

    C.14

    D.-15


    正确答案:C
    解析:本题考查对位运算符的理解和掌握。j的值是将i的值按位取反得到的,所以,将0xFFFFFFF1取反得到0x0000000E,十进制数值为14。故本题答案是C。

  • 第2题:

    阅读下列代码

    Public class Person{

    Static int arr[ ] = new int (10);

    Public static void main (String args ) {

    System.out.println(arr[9]);

    }

    }

    该代码运行的结果是

    A )编译时将产生错误

    B )编译时正确,运行时将产生错误

    C )输出 0

    D )输出空


    正确答案:C

  • 第3题:

    main函数中发生编译错误的语句是______。 include class A { public: int a; const i

    main函数中发生编译错误的语句是______。

    include<iostream.h>

    class A

    {

    public:

    int a;

    const int b;

    A( ):a(10),b(20){}

    void fun( )const

    {

    cout<<"a="<<a<<"\tb="<<b<<endl;

    }

    };

    void main( )

    {

    A obj1;

    const A*ptr=new A;

    ptr=&obj1;

    ptr->a=100;

    ptr->fun( );

    }


    正确答案:ptr->a=100;
    ptr->a=100; 解析:本题考察的是const的使用。const修饰的是指针变量的值,指针本身是可变的,但指针所指对象的值是常量,即ptr->a是不能被改变的。

  • 第4题:

    下面程序的输出结果是什么? class C1{ static int j=0; public void method(int a){ j++; } } class Test extends C1{ public int method(){ return j++; } public void result(){ method(j); System.out.println(j+method()); } public static void main(String args[]){ new Te

    A.0

    B.1

    C.2

    D.3


    正确答案:C

  • 第5题:

    给出下列代码,如何使成员变量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修饰。

  • 第6题:

    阅读下面代码 public class Person { static int arr[]=new int[10]; public static void main(String args) { System.out.println(arr[9]); } } 该代码的运行结果是

    A.编译时将产生错误

    B.编译时正确,运行时将产生错误

    C.输出零

    D.输出空


    正确答案:B
    解析:Java程序中,main()方法的格式为public staric void main(String args[]) { },返回值为void,参数必须为字符数组。本题目程序的参数不是字符数组,编译不会出错,但是运行时会找不到main()方法,程序无法执行。

  • 第7题:

    有如下类定义: class Test { public: Test(){a=0;c=0} //① int f(int a)const{this->a=a;} //② static int g(){return a;} //③ void h(int b){Test::b;}; //④ private: int a; static int b; const int C; }; int Test::b=0; 在标注号码的行中,能被正确编译的是( )。

    A.①

    B.②

    C.③

    D.④


    正确答案:D
    解析:此题考查的是类的定义。一个类的长数据成员的初始化只能在成员初始化列表中进行,故选项A) 错误;常成员函数不能更新对象的数据成员,故选项B) 错误;静态成员函数可以直接访问类中说明的静态成员,但不能直接访问类中说明的非静态成员,故选项C) 错误。

  • 第8题:

    下面的例子中

    using System;

    class A

    {

    public static int X;

    static A(){

    X=B.Y+1;

    }

    }

    class B

    {

    public static int Y=A.X+1;

    static B(){}

    static void Main(){

    Console.WriteLine("X={0},Y={1}",A.X,B.Y);

    }

    }

    产生的输出结果是什么?


    正确答案:
    答:x=1,y=2

  • 第9题:

    有下列程序:includeusing namespace std;class VAC{public: int f() const{return3;}

    有下列程序: #include<iostream> using namespace std; class VAC{ public: int f() const{return3;} int f() {return 5;} }; int main(){ VAC v1; const VAC v2; cout<<v1.f()<<v2.f();

    A.53

    B.35

    C.55

    D.33


    正确答案:A
    解析: 此题考查的是常成员函数的应用。VAC类中说明了两个函数,一个是常成员函数,一个是普通函数;在主函数中说明了两个对象,通过普通对象v1调用的是普通函数,输出5;通过常对象V2调用是常成员函数,输出3。

  • 第10题:

    给出下面代码:public class Person{static int arr[] = new int[10];public static void main(String a[]) {System.out.println(arr[1]);}}以下那个说法正确?

    A. 编译时将产生错误;

    B. 编译时正确,运行时将产生错误;

    C. 输出0;

    D. 输出null。


    正确答案:C

  • 第11题:

    哪一行定义了一个静态变量?()

    • A、public static int i;
    • B、static public int i;
    • C、public int static i;
    • D、int public static i;

    正确答案:A

  • 第12题:

    问答题
    public static const int A=1;这段代码有错误么?是什么?

    正确答案: const不能用static修饰。
    解析: 暂无解析

  • 第13题:

    阅读下列代码后 public class Person{ int arr[]=new int[10]; public static void main(String args[]){ System.out.println(arr[1]); } } 正确的说法是( )。

    A.编译时将产生错误

    B.编译时正确,运行时将产生错误

    C.输出零

    D.输出空


    正确答案:A
    解析:本题考查考生对Java中数组的定义及使用。int arr[]=new int[10]表示数组arr是一个含有10个元素的整数数组。Java中的数据类型必须实例化后才能使用,但是有种情况例外,就是该成员是用static声明的。题目中对于数组并没有实例化,因此不能使用,所以选项A说法正确。如果加上static修饰符,改为 static int arr[]=new int[10]或者将该数组实例化即可,输出为0。

  • 第14题:

    有如下程序 include using namespace std;int i=1;class Fun {public:static int i;i

    有如下程序 #include <iostream>using namespace std;int i=1;class Fun {public:static int i;int value(){ return i-1;}int value()const{ return i+1;}};int Fun:: i=2;int main() {int i=3;Fun fun1;const Fun fun2;______________________return ();}若程序的输出结果是:123

    A.cout<<fun1.value()<<Fun:: i<<fun2.value();

    B.cout<<Fun::i<<fun1.value()<<fun2.value();

    C.cout<<fun1. value()<<fun2.value()<<Fun:: i;

    D.cout<<fun2.value()<<Fun:: i<<fun 1.value();


    正确答案:A

  • 第15题:

    已知如下类说明: 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

  • 第16题:

    给出下列代码,如何使成员变量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

  • 第17题:

    下列代码的执行结果是public class Test{ public int aMethod(){ static int i=0; i++; System.out.println(i); } public static void main(String args[]){ Test test= new Test(); test. aMethod(); }}

    A.编译错误

    B.0

    C.1

    D.运行成功,但不输出


    正确答案:A
    解析:static不能修饰局部变量。

  • 第18题:

    有如下程序:includeusing namespace std;int i=1;class Fun{public:static int i;int

    有如下程序: #include<iostream> using namespace std; int i=1; class Fun { public: static int i; int value(){return i-1;} int value()const{return i+1;} }; int Fun::i=2; int main() { int i=3; Fun fun 1; const Fun fun2; ______ return 0; } 若程序的输出结果是: 123 则程序中横线处的语句是( )。

    A.cout<<fun1.value()<<Fun::i<<fun2.value();

    B.cout<<Fun::i<<fun1.value()<<fun2.value();

    C.count<<fun.value()<<fun2.value()<<Fun::i;

    D.cout<<fun2.value()<<Fun::i<<fun1.value();


    正确答案:A
    解析:此题因为定义的变量i是static类型的(main()函数内部的i只是一个局部变量),所以,选项A)中fun1.value()的返回值是1,Fun::i引用的是外部变量会输出2;fun2.value();会调用常成员函数int valueoconstfrerun i+1;}使得外部静态变量i的值增加为3,故输出3。

  • 第19题:

    public static const int A=1;这段代码有错误么?是什么?


    正确答案:
    答:const不能用static修饰。

  • 第20题:

    下列代码的执行结果是( )。

    public class Test{

    public int aMethod( ){

    static int i=0;

    i++;

    System.out.println(i):

    }

    public static void main (String args[]){

    Trest test=new Test ( );

    test aMethod( ):

    }

    }

    A.编译错误

    B.0

    C.1

    D.运行成功,但不输出

    B.

    C.

    D.


    正确答案:A

  • 第21题:

    有如下类定义: class Test { public: Test{a=0;c=0;}//① int f(im A.const{this->a=a;}//② static int g{return a;f//③ void h(int B.{Test:.b=b;};//④ private: int a; static int b; const int C; }; int Test::b=0: 在标注号码的行中,能被正确编译的是( )。

    A.①

    B.②

    C.③

    D.④


    正确答案:D
    只能通过构造函数的参数初始化列表对常数据成员进行初始化,本题中常数据成员为C。①通过默认构造函数初始化c,所以不正确。常成员函数只能引用本类中数据成员,而不能修改它,所以②不正确。静态成员函数由于没有this指针,所以不能访问本类中的非静态成员,所以③错误。

  • 第22题:

    设有如下代码:

    class Base{}

    public class MyCast extends Base{

    static boolean b1=false;

    static int i = -1;

    static double d = 10.1;

    public static void main(String argv[]){

    MyCast m = new MyCast();

    Base b = new Base();

    //Here

    }

    }

    则在 //Here处插入哪个代码将不出现编译和运行错误。

    A.b=m;

    B.m=b;

    C.d =i;

    D.b1 =i;


    正确答案:AC

  • 第23题:

    代码public static const int A=1;中的错误是()

    • A、 A需要定义类型
    • B、 格式错误
    • C、 const不能用static修饰符
    • D、 const不能用public修饰符

    正确答案:C

  • 第24题:

    单选题
    代码public static const int A=1;中的错误是()
    A

     A需要定义类型

    B

     格式错误

    C

     const不能用static修饰符

    D

     const不能用public修饰符


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