public class Test { public static void main (String args) { class Foo { public int i = 3; } Object o = (Object) new Foo(); Foo foo = (Foo)o; System.out.printIn(foo. i); } } 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.
相似题目
-
package test1; public class Test1 { static int x = 42; } package test2; public class Test2 extends test1.Test1 { public static void main(String[] args) { System.out.println(“x = “ + x); } } What is the result?()
A . x = 0
B . x = 42
C . Compilation fails because of an error in line 2 of class Test2.
D . Compilation fails because of an error in line 3 of class Test1.
E . Compilation fails because of an error in line 4 of class Test2.
-
1.public class Test{ 2.int x=12; 3.public void method(intx){ 4.x+=x; 5.System.out.println(x); 6.} 7.} Given: 34.Test t=new Test(); 35.t.method(5); What is the output from line 5 of the Test class?()
A . 5
B . 10
C . 12
D . 17
E . 24
-
public class Test {public int call(){static int i=0;i++;System.out.println(i);}public static void main(String args[]){Test test = new Test();test.call();}}
-
给定JAVA代码,如下:Class Parent{public void count() {System.out.println(10%3) ;}}public class Test extends Parent{public void count() {System.out.println(10/3) ;}public static void main(Stringargs[]) {Parent p = new Test() ;p.count() ;}}运行编译后,输出结果是()。
-
给定java程序Test.java如下,编译运行,结果是( ) 。package com;class Test {protected void talk () {System.out.print(talk) ; }}给定Test 的子类Test2,代码如下:packagecom.util;import com.*;public class Test2 extends Test {public static void main (String[]args) {new Test2() .talk() ;}
-
给出如下类定义:public class test {test(int k) { }}如果要创建一个该类的对象,正确的语句是:
-
有以下代码:package com;public class Test {public static void main(String[] args) {Test test = new Test();//here}}在here处加上以下什么语句,可以获得Class对象?(多选)
-
public class A{ public static void main(String args[]){ B b = new B(); b.test(); } public void test(){ System.out.print(\A\); } } class B extends A{ void test(){ super.test(); System.out.println(\B\); } }
-
考虑如下类:public class Test {int j,k;public Test(int j ) {this(j,0);}public Test(int j, int k) {this.j=j;this.k=k;}}以下哪些可正确创建Test对象?
-
分析如下所示的Java代码,则选项中的说法正确的是( )。 class Parent{ public String name; public Parent(String pName){ this.name = pName; } } public class Test extends Parent { //1 public Test(String Name){ //2 name=\hello
-
下列程序输出结果为()。 public class test { public static void main (String args[]) {
下列程序输出结果为()。 public class test { public static void main (String args[]) { int a=0; outer:for(int i=0;i<2;i + +) { for(int j=0;j<2;j+ +) { if(j>i) { continue outer; } a+ +; } } System.out.println(a); } }
A.0
B.2
C.3
D.4
-
有如下程序:includeusing namespace std;Class Test{public:Test(){}Test(const Test&t){co
有如下程序: include using namespace std; Class Test{ public: Test(){} Test(const Test&t){cout<<1;} ); Test fun(Test &u){Test t=u;retum t;} int main(){Test X,y;x=fun(y);retum 0;} 运行这个程序的输出结果是()。
A.无输出
B.1
C.11
D.111
-
下列程序的输出结果为()。public class Test {public static void main (String[] args) { int
下列程序的输出结果为()。 public class Test { public static void main (String[] args) { int i,j,k,a=3,b=2; i=(--a==b++)? --a:++b; j=a++; k=b; System. out. println("i="+i+" ,j =" +j+",k ="+k); } }
A.i=2, j=1, k=3
B.i=1, j=1, k=2
C.i=4, j=2, k=4
D.i=1, j=1, k=3
-
下面程序段的输出结果为package test;public class Class A{ int x=20; static int y=6; public
下面程序段的输出结果为 package test; public class Class A { int x=20; static int y=6; public static void main(String args[]) { Class B b=new Class B(); b.go(10); System.out.println("x"+b.x); } } class ClassB { int x; void go(int y) { ClassA a=new ClassA(); x=a.y; } }
A.x=10
B.x-20
C.x=6
D.编译不通过
-
下列语句输出结果为()。 public class test{ public static void main(String args[]) String s1
下列语句输出结果为()。 public class test { public static void main(String args[]) String s1 =newString("HOW"); String s2=newString("How"): System.out.pnntln(!(s1.equals(s2))); } }
A.假
B.真
C.0
D.1
-
有如下类定义: class Test { public: Test(){a=0;c=0;} //① int f(in
有如下类定义: class Test { public: Test(){a=0;c=0;} //① int f(int a)const {this->a=a;} //② static int g(){return a;} //③ void h(int b){Test::b=b;}; //④ private: int a; static int b; const int c; }; int Test::b=0; 在标注号码的行中,能被正确编译的是
A.①
B.②
C.③
D.④
-
有如下程序:include<iostream>using namespace std;class Test{public:Test(){n+=2;}~Test(){n-
有如下程序: include<iostream> using namespace std; class Test{ public: Test() {n+=2;} ~Test() {n-=3;} static int getNum(){return n;} private: static int n; }; int Test::n=1; int main() { Test* p=new Test; delete p; cout<<"n="<<Test::getNum()<<endl; return0; } 执行后的输出结果是()。
A.n=0
B.n=1
C.n=2
D.n=3
-
关于下面的程序Test.java说法正确的是()。public class Test {String x="1";int y;
关于下面的程序Test.java说法正确的是()。
public class Test {
String x="1";
int y;
public static void main(String args[]) {
int z=2;
System.out.println(x+y+z);
}
}
A.3
B.102
C.12
D.程序有编译错误
-
代码三: public class Test03 { public static void main(); } }
-
以下代码可以编译通过 public class Test01 { public static void main(); } }
是
否
-
给定如下代码,下面可以作为该类的构造函数的是()public class Test {}
A.A.public void Test(){}
B.B.public Test() {}
C.C.public static Test(){}
D.D.public static void Test(){}
-
代码四: public class Test04 { public static void main(); n--; } } }
-
Given: public class Test { public static void main (); } } What is the result?
A.An exception is thrown.
B.The code will not compile
C.The program prints “null”
D.The program prints “blue”
E.The program prints “green”
-
已知有如下代码: import java.util.*; public class Test{ public static void main(); } }
A.编译失败,因为list无法加入一个null元素
B.编译成功,运行失败,运行时会抛出NullPointerException
C.编译成功,运行成功,运行结果是: [hello,null]
D.编译成功,运行成功,运行结果是: [hello, hello, null]
-
下列代码中,将引起一个编译错误的行是 1) public class Test 2) int m,n; 3) public Test() 4) public Test(int
A.m=a;
5