以下语句能顺利通过编译: class class1 { protected int i=5; //i为保护属性 } public class class2 { public static void main(String args[]) { class1 cs1=new class1(); System.out.println(cs1.i); } }。()此题为判断题(对,错)。

题目
以下语句能顺利通过编译: class class1 { protected int i=5; //i为保护属性 } public class class2 { public static void main(String args[]) { class1 cs1=new class1(); System.out.println(cs1.i); } }。()

此题为判断题(对,错)。


相似考题
更多“以下语句能顺利通过编译: class class1 { protected int i=5; //i为保护属性 } public class class2 { public static void main(String args[]) { class1 cs1=new class1(); System.out.println(cs1.i); } }。() 此题为判断题(对,错)。”相关问题
  • 第1题:

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

  • 第2题:

    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 来明确。

  • 第3题:

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

    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

  • 第4题:

    以下程序的编译和运行结果为?class test {static boolean check;public static void main(String args[]) {int i;if(check == true)i=1;elsei=2;if(i= 2、i=i+2;else i = i + 4;System.out.println(i);}}

    A. 3

    B. 4

    C. 5

    D. 6

    E. 语句if(i= 2、编译出错


    正确答案:E

  • 第5题:

    以下的程序的调试结果为?public class MyAr{public static void main(String argv[]) {MyAr m = new MyAr();m.amethod();}public void amethod(){static int i;System.out.println(i);}}

    A. 输出结果为 0

    B. 运行出错

    C. 输出结果为 null

    D. 编译错误


    正确答案:D

  • 第6题:

    以下程序能顺利通过编译: public class am_I_right { public static void main(String args[]) { this.toString(); } String toString() { retur。()

    此题为判断题(对,错)。


    答案:错

  • 第7题:

    以下语句能顺利通过编译: final class class1 { } class class2 extends class1 { } 。()

    此题为判断题(对,错)。


    答案:错

  • 第8题:

    以下语句能顺利通过编译: class class1 { private int i=5; //i为私有属性!! } public class class2 { public static void main(String args[]) { class1 cs1=new class1(); System.out.println(cs1.i); } } 。()

    此题为判断题(对,错)。


    答案:错

  • 第9题:

    设有程序如下: abstract class absclass { abstract void method1(); } class conclass extends absclass { public void method1() { System.out.println("子类");} } public class mainclass { public static void main(String args[]) { absclass ac1=new absclass(); //语句1 absclass ac2=new conclass(); //语句2 ac2.method1(); //语句3 } } 则main()方法中的第一条语句(即语句1)可以顺利通过编译。()

    此题为判断题(对,错)。


    答案:错

  • 第10题:

    给定如下Java程序片断:  class A{  public A (){   System.out.println("A");  } }  class B extends A{  public B(){  System.out.println("B"); }  public static void main(String[] args){    B b=new B();  } }  上述程序将()。 

    • A、不能通过编译
    • B、通过编译,输出为:A B
    • C、通过编译,输出为:B
    • D、通过编译,输出为:A

    正确答案:B

  • 第11题:

    对于下列代码: 1) class Person {   2} public void printValue(int i, int j) {//... }     3} public void printValue(int i){//... }    4} }   5) public class Teacher extends Person { 6} public void printValue( ) {//... }     7} public void printValue(int i) {//...}     8} public static void main(String args[]){     9} Person t = new Teacher( );     10} t.printValue(10);     11} } 第10行语句将调用哪行语句?()

    • A、 line 2
    • B、 line 3
    • C、 line 6
    • D、 line 7

    正确答案:D

  • 第12题:

    单选题
    class Super {  public int i = 0;  public Super(String text) {  i = 1; }  }  public class Sub extends Super {  public Sub(String text) {  i = 2;  }   public static void main(String args[]) {  Sub sub = new Sub(“Hello”);  System.out.println(sub.i);  }  }  What is the result?()
    A

     0

    B

     1

    C

     2

    D

     Compilation fails.


    正确答案: B
    解析: This code is perfectly legal and the answer is C. 

  • 第13题:

    public class Something {

    public static void main(String[] args) {

    Other o = new Other();

    new Something().addOne(o);

    }

    public void addOne(final Other o) {

    o.i++;

    }

    }

    class Other {

    public int i;

    }

    和上面的很相似,都是关于final 的问题,这有错吗?


    正确答案:

     

    正确。在addOne method 中,参数o 被修饰成final。如果在addOne method 里我们修

    改了o 的reference

    (比如: o = new Other();),那么如同上例这题也是错的。但这里修改的是o 的member vairable

    (成员变量),而o 的reference 并没有改变。

  • 第14题:

    4 . 写出程序的输出结果

    class Class1 {

    private string str = "Class1.str";

    private int i = 0;

    static void StringConvert(string str) {

    str = "string being converted.";

    }

    static void StringConvert(Class1 c) {

    c.str = "string being converted.";

    }

    static void Add(int i) {

    i++;

    }

    static void AddWithRef(ref int i) {

    i++;

    }

    static void Main() {

    int i1 = 10;

    int i2 = 20;

    string str = "str";

    Class1 c = new Class1();

    Add(i1);

    AddWithRef(ref i2);

    Add(c.i);

    StringConvert(str);

    StringConvert(c);

    Console.WriteLine(i1);

    Console.WriteLine(i2);

    Console.WriteLine(c.i);

    Console.WriteLine(str);

    Console.WriteLine(c.str);

    }

    }


    正确答案:
     

  • 第15题:

    下列语句执行后,i的值是( )。 public class Test { public static void main(String[ ] args) { int i =0; for(int j=10; j>5&&i<5; j-=3,i+=2) i=i+j; System.out.println(i); } }

    A.8

    B.9

    C.10

    D.12


    正确答案:D
    解析:变量i和j的初始值分别为0和10,判断结束条件j>5&&i5为true,执行i=i+j;得到i=10,再做j-=3和i+=2,分别得到i=12和j=7,判断结束条件j>5&&i5为false,停止循环,因此i的值为12,正确答案为D。

  • 第16题:

    以下程序调试结果为:

    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

  • 第17题:

    以下的程序的调试结果为public class Scope{int i;public static void main(String argv[]){Scope s = new Scope();s.amethod();}public static void amethod(){System.out.println(i);}}

    A. 输出结果为:0

    B. 无输出

    C. 编译错误

    D. 输出null


    正确答案:C

  • 第18题:

    以下语句能顺利通过编译: abstract class class1 { } public class mainClass { public static void main(String args[]) { class1 cs1=new class1(); } } 。()

    此题为判断题(对,错)。


    答案:错

  • 第19题:

    以下语句能顺利通过编译: class test { static void sayHello() { this.toString(); } public String toString() { retur。()

    此题为判断题(对,错)。


    答案:错


  • 第20题:

    以下语句能顺利通过编译: class class1 { private final void method1() {} }。()

    此题为判断题(对,错)。


    答案:对

  • 第21题:

    以下语句能顺利通过编译: class class1 { private final method1() {} } 。()

    此题为判断题(对,错)。


    答案:错

  • 第22题:

    class Super {  public int i = 0;  public Super(String text) {  i = 1; }  }  public class Sub extends Super {  public Sub(String text) {  i = 2;  }   public static void main(String args[]) {  Sub sub = new Sub(“Hello”);  System.out.println(sub.i);  }  }  What is the result?()  

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

    正确答案:C

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