1.public class Test {  2.public static void main (String arg

题目
单选题
1.public class Test {  2.public static void main (String args[]) {  3.class Foo {  4.public int i = 3;  5.}  6.Object o = (Object) new Foo();  7.Foo foo = (Foo)o;  8.System.out.printIn(foo. i); 9. }  10.}   What is the result?()
A

 Compilation will fail.

B

 Compilation will succeed and the program will print “3”

C

 Compilation will succeed but the program will throw a ClassCastException at line 6.

D

 Compilation will succeed but the program will throw a ClassCastException at line 7.

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第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.f;


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

第2题:

下列程序的输出结果是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正确。

第3题:

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

public class Test {

public static void main (String args[]) {

String s1="hello!";

System.out.println (s1.toUpperCase());

}}


正确答案:HELLO!
HELLO! 解析:在String类的常用方法中,toUpperCaee()方法将当前字符串中的所有小写字母转化成大写,其他字符保持不变。

第4题:

Which declarations will allow a class to be started as a standalone program?()  

  • A、public void main(String args[])
  • B、public void static main(String args[])
  • C、public static main(String[] argv)
  • D、final public static void main(String [] array)
  • E、public static void main(String args[])

正确答案:D,E

第5题:

main方法是JavaApplication程序执行的入口点。关于main方法的方法头,下列合法的是( )。

A.public static void main()

B. public static void main(String[])args)

C. public static iht main(String[]arg)

D.public void main(String arg[])


正确答案:B

第6题:

下列程序的输出结果是public class fff { void printValue (int m) { do { System.out.println("The value is" +m); } while(--m>10) } public static void main (String arg[]) { int i=10; Test t= new Test(); t. printValue(i); }}

A.8

B.9

C.10

D.11


正确答案:C
解析:do-while最少被执行一次,在执行完do中的内容后判断while中的条件是否为true,如果为true的话就再执行do中的内容,然后再进行判断,以此类推直到while的判断为false时,退出循环并执行循环后面的语句。--操作符在变量左边的是先将变量的值减1再运算。

第7题:

main方法是Java Application程序执行的入口点,关于main方法头以下( )是合法的。

A.pubUc statk void main()

B.public static void main (String[]args)

C.public static int main (String[]arg)

D.public void main (String arg[])


正确答案:B

第8题:

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

第9题:

执行以下代码会输出什么结果?()   public class Test {    StringgetStr(String s){  return s + “hello”;  }  public static void main(String arg[]) {           Test t= new Test();  System.out.println(t.getStr(“LiLei/n”));     } } 

  • A、 编译报错
  • B、 LiLei    hello
  • C、 LiLeihello
  • D、 无任何输出

正确答案:B

第10题:

Public class test (  Public static void main (String args[])  (  System.out.printIn (6 ^ 3);  )  )   What is the output?()


正确答案:5

更多相关问题