CMS专题

单选题1. public class ArrayTest {  2. public static void main (String[]args)  {  3. float f1[], f2[];  4. f1 = new float [10];  5. f2 = f1;  6. System.out.printIn (“f2[0]=” + f2[0]);  7.  }  8. }   What is the result?()AIt prints f2[0] = 0.0BIt prints f2[0] 

题目
单选题
1. public class ArrayTest {  2. public static void main (String[]args)  {  3. float f1[], f2[];  4. f1 = new float [10];  5. f2 = f1;  6. System.out.printIn (“f2[0]=” + f2[0]);  7.  }  8. }   What is the result?()
A

 It prints f2[0] = 0.0

B

 It prints f2[0] = NaN

C

 An error at line 5 causes compile to fail.

D

 An error at line 6 causes compile to fail.

E

 An error at line 6 causes an exception at runtime.

参考答案和解析
正确答案: A
解析: 暂无解析
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

下列程序的运行结果是______。include class Base { public: void f(int x){cout<<“B

下列程序的运行结果是______。

include<iostream.h>

class Base

{

public:

void f(int x){cout<<“Base:”<<x<<endl;}

);

class Derived:public Base

{

public:

void f(char*str){cout<<“Derived:”<<str<<endl;}

};

void main(void)

{

Base*pd=ne


正确答案:Base:97。
Base:97。 解析: 本题主要考查两个知识点,一是基类指针可以指向派生类对象,并可以访问派生类的所有成员。二是在函数重载中进行隐式类型转换。如pd->f(‘a’);系统到底调用哪个重载函数呢?实参既不是派生类中的形参,也不是基类中f函数的形参类型。此时系统根据就近原则和从高优先级到低优先级的规则尝试隐式转换。单字符更接近整数,故调用的是基类的f函数。

第2题:

写出程序的输出结果

public abstract class A

{

public A()

{

Console.WriteLine('A');

}

public virtual void Fun()

{

Console.WriteLine("A.Fun()");

}

}

public class B: A

{

public B()

{

Console.WriteLine('B');

}

public new void Fun()

{

Console.WriteLine("B.Fun()");

}

public static void Main()

{

A a = new B();

a.Fun();

}

}


正确答案:
 

第3题:

以下Java应用程序执行入口main方法的声明中,正确的是( )。

A.public static void main()

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

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

D.public void main(String[] args)


参考答案:B

第4题:

1. public class Outer{  2. public void someOuterMethod() {  3. // Line 3  4. }  5. public class Inner{}  6. public static void main( String[]argv ) {  7. Outer o = new Outer();  8. // Line 8  9. }  10. }  Which instantiates an instance of Inner?()  

  • A、 new Inner(); // At line 3
  • B、 new Inner(); // At line 8
  • C、 new o.Inner(); // At line 8
  • D、 new Outer.Inner(); // At line 8

正确答案:A

第5题:

以下是JAVA中正确的入口方法是? () 

  • A、 public static void main(String[] args){}
  • B、 public static void main(String args){}
  • C、 public void main(String[] args){}
  • D、 public static int main(String[] args){}

正确答案:A

第6题:

阅读下面程序 public class ConcatTest{ public static void main(String[] args) { String strl = "abc"; String str2 = "ABC"; String str3 = str1.concat(str2); System.out.println(str3); } } 程序的运行结果是:

A.abe

B.ABC

C.abcABC

D.ABCabc


正确答案:C
解析:本题考查字符串的使用。String类提供concat(str)方法,该方法将当前字符串对象与指定str字符串相连。题目程序中生成两个字符串变量str1和str2,并为其赋值,然后生成一个字符串变量str3,该字符串变量的值为表达式str1.concat(str2)的结果。表达式str1.concat(str3)是把字符串str1与字符串str2相连,结果为“abcABC”。
因此,程序的运行结果是“abcABC”。本题的正确答案是选项C。

第7题:

以下哪个是Java应用程序main方法的有效定义?

A. public static void main();

B. public static void main( String args );

C. public static void main( String args[] );

D. public static void main( Graphics g );

E. public static boolean main( String a[] );


正确答案:C

第8题:

下面代码的运行结果是( )。 public class ConcatTest { public static void main (String[ ] args) { String str1 = "abc"; String str2 = "ABC"; String str3 = str1. coneat(str2); System. out. println(str3); } }

A.abc

B.ABC

C.abcABC

D.ABCabc


正确答案:C
解析:String类的concat方法原型为public String concat (String str),其功能是将指定字符串连到此字符串的末尾。如果参数字符串的长度为0,则返回此String对象。否则,创建一个新的String对象,用来表示由此String对象表示的字符序列和由参数字符串表示的字符序列串联而成的字符序列。所以本题中的结果为str1和str2串联而成的字符序列,即“abcABC”。

第9题:

public class TestString 1 {  public static void main(String[] args) {  String str = “420”;  str += 42;  System.out.print(str);  }  }  What is the output?()

  • A、 42
  • B、 420
  • C、 462
  • D、 42042
  • E、 Compilation fails.
  • F、 An exception is thrown at runtime.

正确答案:D

第10题:

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

更多相关问题