编译、运行下面代码将发生() class Test{ sataic int mtArg=1; public static void main(String[] args){ int myArg; System.out.println(myArg); } }A.代码被编译,运行时输出0B.代码被编译,运行时输出1C.编译错,因为局部变量和类变量有相同的名字D.编译错,因为局部变量在使用之前没有被初始化

题目

编译、运行下面代码将发生() class Test{ sataic int mtArg=1; public static void main(String[] args){ int myArg; System.out.println(myArg); } }

A.代码被编译,运行时输出0

B.代码被编译,运行时输出1

C.编译错,因为局部变量和类变量有相同的名字

D.编译错,因为局部变量在使用之前没有被初始化


相似考题
更多“编译、运行下面代码将发生() class Test{ sataic int mtArg=1; public static void main(String[] args){ int myArg; System.out.println(myArg); } }”相关问题
  • 第1题:

    下面程序的输出结果是什么? 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

  • 第2题:

    如下两个源程序文件,分别编译后,运行Example.class文件,运行结果为______。

    AB.java文件代码如下;

    package test;

    public class AB

    {

    int a=60;

    public void show()

    {

    System.out.println(”a=”+a);

    }

    Example.java文件代码如下:

    import test.AB;

    class Example

    {

    public static void main(String args[])

    {

    AB bj=new AB();

    obj.show();

    }

    }


    正确答案:a=60
    a=60

  • 第3题:

    阅读下面代码 public class Test { String s="One World One Dream"; public static void main(String[] args) { System.out.println(s); } } 其运行的结果是

    A.args

    B.World One Dream

    C.s

    D.编译时出错


    正确答案:D

  • 第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题:

    下列程序的输出结果是class Test{public static void main(String args[]){int n=7;n<<=3;n=n&am

    下列程序的输出结果是 class Test{ public static void main(String args[]){ int n=7; n<<=3; n=n&n+1|n+2^n+3; n>>=2; System.out.println(n); } }

    A.0

    B.-1

    C.14

    D.64


    正确答案:C
    解析:本题考查Java中的运算符。首先要清楚程序里面涉及的运算符的含义。“”是按位左移运算符,“&”是按位与运算符,“|”是按位或运算符,“^”是按位异或运算符。题目中整型变量n=7相当于二进制中的111,n=3语句执行后,n值为111000,相当于十进制的56,而语句n=n&n+1|n+2^n+3执行后,n值为57;n>>=2语句执行后,n的值为14,所以选项C正确。

  • 第6题:

    下面程序代码运行结果为( )。 import java.awt.*; public class Test { public static void main (String args[]) { String s1="a+b+c"; String s2="+"; int i=s1.lastIndexOf (s2); System.out.println(i); } }

    A.0

    B.1

    C.2

    D.3


    正确答案:D
    解析:lastIndexOf方法返回一个整数值,指出String对象内子字符串的最后一次出现的开始位置下标。如果没有找到子字符串,则返回-1。本题中子串“+”在字符串“a+b+c”中出现了两次,最后一次出现的起始位置为3。

  • 第7题:

    interface A{

    int x = 0;

    }

    class B{

    int x =1;

    }

    class C extends B implements A {

    public void pX(){

    System.out.println(x);

    }

    public static void main(String[] args) {

    new C().pX();

    }

    }


    正确答案:

     

    错误。在编译时会发生错误(错误描述不同的JVM 有不同的信息,意思就是未明确的

    x 调用,两个x 都匹配(就象在同时import java.util 和java.sql 两个包时直接声明Date 一样)。

    对于父类的变量,可以用super.x 来明确,而接口的属性默认隐含为 public static final.所以可

    以通过A.x 来明确。

  • 第8题:

    下面程序段的输出结果为 package test; public class A { int x=20; static int y=6; public static void main(String args[]) { Class B b=new Class B(); b.go(10); System.out.println(”x=”+b.x); } } class Class B { int x; void go(int y) { ClassA a=new ClassA(); x=a.y; } }

    A.x=10

    B.x=20

    C.x=6

    D.编译不通过


    正确答案:C
    解析:本题考查在Java中静态变量(类变量)的用法。在题目程序段中生成了一个staticinty=6类变量,在ClassA中调用的b.go(10),只不过是在ClassB中的一个局部变量,通过调用ClassB中的go方法可以生成一个ClassA对象,并给这个新生成的对象赋以ClassA中的类变量y的值。从main()方法作为入口执行程序,首先生成一个ClassB的对象,然后b.go(10)会调用ClassA,会给x和y赋值,x=a.y后,x值为6,再返回去执行System.out.println(”x=”+b.x)语句,输出为x=6,可见,正确答案为选项C。

  • 第9题:

    2给出下列的程序,其叙述正确的是( )。public class Man{static int arr[]=new int[10];public static void main(String args[]){System.out.println (arr[1=];}}

    A.编译时将发生错误

    B.编译时正确但是运行时出错

    C.输出为0

    D.输出为null


    正确答案:C

  • 第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题:

    编译如下Java程序片断:  class test{  int count = 9;  public void a(){    int count=10;  System.out.println("count 1 =" + count);  }  public void count(){  System.out.println("count 2 =" + count);  }  public static void main(String args[]){    test t=new test();    t.a();   t.count();   } }  结果将()。    

    • A、不能通过编译
    • B、输出:       count 1 = 10        count 2 = 9
    • C、输出:          count 1 = 9          count 2 = 9

    正确答案:B

  • 第12题:

    单选题
    public class Test {  public int aMethod() {  static int i = 0;  i++;  return i;  }  public static void main (String args[]) {  Test test = new Test();  test.aMethod();  int j = test.aMethod();  System.out.println(j);  }  }  What is the result?()
    A

     0

    B

     1

    C

     2

    D

     Compilation fails.


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

  • 第13题:

    下列程序的执行结果是 ( ) public class Test { public int aMethod() { satic 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

  • 第14题:

    下列代码的执行结果是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不能修饰局部变量。

  • 第15题:

    阅读下面代码 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()方法,程序无法执行。

  • 第16题:

    下列程序段运行的结果为 public class Test{ static void print(String s,int i){ System.out.println("String:"+s+",int:"+i); } static void print(int i, String s){ System.out.println("int:"+i+",String:"+s); } public static void main(String [] args){ print(99,"Int first"); } }

    A.String:Stringfirst,int:11

    B.int:11,String:Int first

    C.String:String first,int:99

    D.int:99,String:int first


    正确答案:D
    解析:本题考查考生阅读程序的能力。JavaApplication都是以main()方法作为入口,首先执行的是print(99,“Intfirst”),根据构造方法的参数类型选择调用方法,这里调用的是print(inti,Strings)方法,因此输出的是int:99,String:Intfirst。

  • 第17题:

    下面代码的运行结果是 public class Test{ public static void main(String args[]){ for(int i=0; i<3;i++){ if(i<2) continue; System.out.println(i); } } }

    A.0

    B.1

    C.2

    D.3


    正确答案:C
    解析:本题考查简单的Java控制语句。题目非常简单,但还是应该细心。这里应注意continue语句。continue语句是跳过循环体中下面尚未执行的语句,回到循环体的开始继续下一轮的循环。当然,在下一轮循环开始前,要先进行终止条件的判断,以决定是否继续循环。对于for语句,在进行终止条件的判断前,还要先执行迭代语句。题目所给程序中,当i=0和i=1时,都会执行continue语句,而不会执行System.out.println(i)语句,只有当i=2时才执行System.out.println(i)语句,输出为2,选项C正确。

  • 第18题:

    下面程序执行后,baz的值应是______。 public class Test9 { public static void main(String[] args) { int index = 1; int fox[] = new int [3]; iht bar = fox [index]; int baz = bar + index; System.out.println(baz); } }

    A.0

    B.1

    C.2

    D.编译错误


    正确答案:B
    解析:int fox[]=new int[3]这时数组的每个元素都初始化为0,所以int baz=bar+index;,其实,这时bar的值为0,这样便有baz的值为1。

  • 第19题:

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

    A.编译时将产生错误

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

    C.输出零

    D.输出空


    正确答案:C
    C。【解析】arr[]为整型数组,分配地址后默认值为0,所以创建数组时也是对每个数组元素赋初值0。

  • 第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题:

    给出下面的程序: public class ex49 { static int arr[] = new int[10]; public static void main(String args [] ) { System.out.println (art [1] ); } } ______叙述是正确的。

    A.编译时将发生错误

    B.输出为 null

    C.输出为0

    D.编译时正确但是运行时出错


    正确答案:C

  • 第22题:

    以下程序调试结果为:

    public class Test {

    int m=5;

    public void some(int x) {

    m=x;

    }

    public static void main(String args []) {

    new Demo().some(7);

    }

    }

    class Demo extends Test {

    int m=8;

    public void some(int x) {

    super.some(x);

    System.out.println(m);

    }

    }

    A.5

    B.8

    C.7

    D.无任何输出

    E.编译错误


    正确答案:B

  • 第23题:

    public class Test {  public int aMethod() {  static int i = 0;  i++;  return i;  }  public static void main (String args[]) {  Test test = new Test();  test.aMethod();  int j = test.aMethod();  System.out.println(j);  }  }  What is the result?()  

    • A、 0
    • B、 1
    • C、 2
    • D、 Compilation fails.

    正确答案:D

  • 第24题:

    单选题
    编译如下Java程序片断:  class test{  int count = 9;  public void a(){    int count=10;  System.out.println("count 1 =" + count);  }  public void count(){  System.out.println("count 2 =" + count);  }  public static void main(String args[]){    test t=new test();    t.a();   t.count();   } }  结果将()。
    A

    不能通过编译

    B

    输出:       count 1 = 10        count 2 = 9

    C

    输出:          count 1 = 9          count 2 = 9


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