单选题class Parser extends Utils {  public static void main (String [] args) {  try { System.out.print(new Parser().getInt("42"));  } catch (NumberFormatException n) {  System.out.println("NFExc "); }  }  int getInt(String arg) throws NumberFormatException {

题目
单选题
class Parser extends Utils {  public static void main (String [] args) {  try { System.out.print(new Parser().getInt("42"));  } catch (NumberFormatException n) {  System.out.println("NFExc "); }  }  int getInt(String arg) throws NumberFormatException {  return Integer.parseInt(arg);  }  }  class Utils {  int getInt(String arg) { return 42; }  }  结果为:()
A

42

B

NFExc

C

42NFExc

D

编译失败

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

第1题:

下列程序创建了一个线程并运行,请在下划线处填入正确代码。

public class Try extends Thread{

public static void main(String args[]){

Threadt=new Try();

【 】;

}

public void run(){

System.out.println(“Try!”);

}

}


正确答案:i
i

第2题:

现有:  class Parser extends Utils  { public static void main (String[]  args)    {     try{System.out.print (new Parser().getlnt("42"));      } catch (Exception e)    {      System.out.println("Exc");  }      }  int getlnt (String arg) throws Exception  {      return Integer.parselnt (arg);      }       class Utils  {  int getlnt (String arg)    {return 42;  }      }      结果为()    

  • A、 42
  • B、 Exc
  • C、 42Exc
  • D、编译失败

正确答案:D

第3题:

classParserextendsUtils{publicstaticvoidmain(String[]args){try{System.out.print(newParser().getInt("42"));}catch(NumberFormatExceptionn){System.out.println("NFExc");}}intgetInt(Stringarg)throwsNumberFormatException{returnInteger.parseInt(arg);}}classUtils{intgetInt(Stringarg){return42;}}结果为:()

A.42

B.NFExc

C.42NFExc

D.编译失败


参考答案:A

第4题:

现有:   class Parser extends Utils {   public static void main(String [] args) {     System.out.print(new Parser().getInt("42"));    }   int getInt(String arg) {  return Integer.parseInt(arg);  }    }   class Utils {     int getInt(String arg) throws Exception { return 42; }    }    结果为()  

  • A、 42
  • B、 编译失败。
  • C、 无输出结果。
  • D、 运行时异常被抛出。

正确答案:A

第5题:

现有  class Parser extends Utils {  public static void main (String  []  args)  {  try  {  System.out.print (new Parser () .getlnt ("42"))       }  catch (Exception e) {  System.out.println ("Exc") ;  }      }  int getlnt (String arg)  throws Exception  {     return Integer.parselnt (arg) ;      }      }  class Utils {  int getlnt ()  {  return 42;  }     }  结果是什么?()      

  • A、 42Exc
  • B、 Exc
  • C、 42
  • D、编译失败

正确答案:C

第6题:

public static void parse(String str) {  try {  float f= Float.parseFloat(str);  } catch (NumberFormatException nfe) {  f= 0;  } finally {  System.out.println(f);  }  }  public static void main(String[] args) {  parse(”invalid”);  }  What is the result?() 

  • A、 0.0
  • B、 Compilation fails.
  • C、 A ParseException is thrown by the parse method at runtime.
  • D、 A NumberFormatException is thrown by the parse method at runtime.

正确答案:B

第7题:

现有:  class Parser (类)extends(继承) Utils {   public static void main(String [] args) {   System.out.print(输出打印)(new Parser().getInt("42"));  }   int getInt(String arg) {   return Integer.parseInt(arg);    }   }   class Utils {   int getInt(String arg) throws Exception { return 42; }  }   结果为:()  

  • A、 42
  • B、 编译失败。
  • C、 无输出结果。
  • D、 运行时异常被抛出。

正确答案:A

第8题:

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

第9题:

class Number {  public static void main(String [] args) {  try {  System.out.print(Integer.parseInt("forty ")); } catch (RuntimeException r) {  System.out.print("runtime ");  } catch (NumberFormatException e) {  System.out.print("number ");  }  }  }  结果是什么?() 

  • A、forty
  • B、number
  • C、runtime
  • D、编译失败

正确答案:D

第10题:

public class Test {  public static void aMethod() throws Exception {  try {  throw new Exception(); } finally {  System.out.println(“finally”);  }  }  public static void main(String args[]) {  try {  aMethod();  } catch (Exception e) {  System.out.println(“exception”);  }  System.out.println(“finished”);  }  }  What is the result?()  

  • A、 finally
  • B、 exception finished
  • C、 finally exception finished
  • D、 Compilation fails.

正确答案:C

更多相关问题