网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
【分录题】(9-2)请阅读程序,写出程序运行结果。 public class Demo8 { public static void main(String args[]) { int b = get(); System.out.println(b); } public static int get() { try { return 1; } finally { return 2; } } }
参考答案和解析
B
更多 “【分录题】(9-2)请阅读程序,写出程序运行结果。 public class Demo8 { public static void main(String args[]) { int b = get(); System.out.println(b); } public static int get() { try { return 1; } finally { return 2; } } }” 相关考题
考题
class A{public int getNumber(int a){return a+1;}}class B extends A{public int getNumber(int a, char c){return a+2;}public static void main(String[] args){B b=new B();System.out.println(b.getNumber(0));}}what is the result?()A.compilation succeeds and 1 is printedB.compilation succeeds and 2 is printedC.compilation succeeds and 3 is printedD.An error at this program cause compilation to fail
考题
下列程序段运行的结果为 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:String first,int:11B.int:11,String:Int firstC.String:String first,int99D.int:99,String:Int first
考题
下列程序的功能是为变量赋值,程序运行后,输出i=51。请改动main方法中的错误,使程序能够正确编译、运行并输出正确的结果。注意:不改动程序结构。class A{private int a;public void setA (int x){a=x;}public int getA(){return a;}}public class MethodTest{public static void main(String args[]){A a=A();a.getA(51);int i=a.getA();System.out.println ("i="+i);}}
考题
下面程序的输出结果是什么? 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 TeA.0B.1C.2D.3
考题
下列程序段运行的结果为 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:11B.int:11,String:Int firstC.String:String first,int:99D.int:99,String:int first
考题
下列程序的输出结果是class Test{public static void main(String args[]){int n=7;n
下列程序的输出结果是 class Test{ public static void main(String args[]){ int n=7; n<<=3; n=nn+1|n+2^n+3; n>>=2; System.out.println(n); } }A.0B.-1C.14D.64
考题
下列程序段中,正确的是______。 ①class MvClass { int var = 100; static int getVar() { return var; } } ②public class MyClass { final int date; void MyClass (int d) { date = d; } } ③public class MyMain { public static void main(String args[]) { System.out.println(Myclass1.date); } } class MyClass1 { int data = 10; } ④class IamAbstract { final int f; double d; abstrct void method(); }A.②④B.①③C.②D.以上都不对
考题
执行下面程序,显示的结果为( )。 public class Test { public static void main (String args[]) { Test t=newTest(); System.out.println (Loverload ("2","3")); } int overload (intx,int y) {return x+y;} String overload (String x,Stnng y){return x+y;} }A.2B.3C.5D.23
考题
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();}}
考题
下列程序的执行结果是 ( ) public class ex68{ public static void main(String[]args){ ex68 obj=new ex68(); int s=0; for(int i=1;i<=4;i++){ s+=obj.method(i); } System.out.println(s); } public int method(int n){ if(n==1) return 1; else return n*method(n-1); } }A.3B.9C.33D.153
考题
以下程序运行后输出的结果是______。public class exl7{public static void main(String args []){int a = 0;for(int j = 1; j <= 20; j++)if(j%5 != 0)a = a + j;System.out.println (a);
考题
以下程序的输出结果为:public class test {public static void main(String args[]) {int s=0;for (int k=0;ks+=method(2,k)-1;System.out.println(s);}public static int method(int n,int m) {if (m==0)return 1;elsereturn n*method(n,m-1、;}}A. 2048B. 1024C. 2036D.2000
考题
阅读以下说明和Java程序,将应填入(n)处的字句写在对应栏内。[说明]下面程序输出一个矩形面积,以及矩形区域上的假想的作物产量。[Java程序]public class MainJava {public static void main(String[] args){Lot_size small=new Lot_size();Lot_size medium=new Lot_size();small.set(5,5,5,25);medium.set(10,10,10,50);System.out.println("For a small lot of area"+small.get_area()+"\n");System.out.println("the actual crops are $"+small.get_data2()+"\n");System.out.println("and ideal crops are $"+small.get data()+"\n");System.out.println("For a medium lot of area"+medium.get_area()+“\n”);System.out.println("the actual crops are $"+medium.get_data2()+"\n");System.out.println ("and ideal crops are $"+medium.get_data()+"\n");}}class Crop_assessment{private int actual_crop;private int ideal_crop;public void set(int in_actual,int in ideal){actual_crop=in_actual;ideal_crop=in_ideal;}public int get_actual_crop(){return (1) ;}public int get_ideal_crop()(return (2) ;}}class Lot_size{private int length;private int width;private Crop_assessment crop= (3) ;public void set(int 1,int W,int a,int i){length=1;width=W;crop.set(a,i);}public int get_area(){return length*width;}public int get_data()freturn (4) ;}public int get_data2()(return (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){}
考题
程序: class TestApp{ public static void main(String[] args){ System.out.println(multiply(2,3,4,5)); } public int multiply(int[] nums){ int result = 1; for(int x :nums) result *= x; return result; } } 程序运行后的输出是哪项?() A、 14B、 编译错误C、 120D、 24
考题
现有: 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、 42B、 ExcC、 42ExcD、编译失败
考题
class TestApp{ public static void main(String[] args){ System.out.println(multiply(2,3,4,5)); } public int multiply(int… nums){ int result = 1; for(int x :nums) result *= x; //result =result*x; return result; } } 2、6、24、120 程序运行后的输出是哪项?() A、 14B、 编译错误C、 120D、 24
考题
作为Java应用程序入口的main方法,其声明格式可以是()。A、public static void main(String[] args)B、public static int main(String[] args)C、public void main(String[] args)D、public int main(String[] args)
考题
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、 finallyB、 exception finishedC、 finally exception finishedD、 Compilation fails.
考题
class Top { static int x = 1; public Top(int y) { x *= 3; } } class Middle extends Top { public Middle() { x += 1; } public static void main(String [] args) { Middle m = new Middle(); System.out.println(x); } } 结果为:() A、1B、2C、3D、编译失败
考题
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、 0B、 1C、 2D、 Compilation fails.
考题
public class Foo { public static void main(String[] args) { try { return; } finally { System.out.println( “Finally” ); } } } What is the result?()A、 FinallyB、 Compilation fails.C、 The code runs with no output.D、 An exception is thrown at runtime.
考题
class TestApp{ public static void main(String[] args){ System.out.println(multiply(2,3,4,5)); } public int multiply(int... nums){ int result=1; for(int x:nums) result*=x; return result; } } 程序运行后的输出是哪项?() A、120B、24C、14D、编译错误
考题
单选题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
0B
1C
2D
Compilation fails.
考题
单选题程序: class TestApp{ public static void main(String[] args){ System.out.println(multiply(2,3,4,5)); } public int multiply(int[] nums){ int result = 1; for(int x :nums) result *= x; return result; } } 程序运行后的输出是哪项?()A
14B
编译错误C
120D
24
考题
单选题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
42B
NFExcC
42NFExcD
编译失败
考题
单选题class TestApp{ public static void main(String[] args){ System.out.println(multiply(2,3,4,5)); } public int multiply(int... nums){ int result=1; for(int x:nums) result*=x; return result; } } 程序运行后的输出是哪项?()A
120B
24C
14D
编译错误
考题
单选题public class Foo { public static void main(String[] args) { try { return; } finally { System.out.println( “Finally” ); } } } What is the result?()A
FinallyB
Compilation fails.C
The code runs with no output.D
An exception is thrown at runtime.
热门标签
最新试卷