Compilation fails.
An exception is thrown at runtime.
doStuffx=6 main x=6
doStuffx=6 mainx =7
doStuffx=7 mainx =6
doStuffx=7 mainx =7
第1题:
public class Yippee2 { static public void main(String [] yahoo) { for(int x= 1; x
第2题:
Given a file GrizzlyBear.java: 1. package animals.mammals; 2. 3. public class GrizzlyBear extends Bear { 4. void hunt() { 5. Salmon s = findSalmon(); 6. s.consume(); 7. } 8. } and another file, Salmon.java: 1. package animals.fish; 2. 3. public class Salmon extends Fish { 4. void consume() { /* do stuff */ } 5. } Assume both classes are defined in the correct directories for theft packages, and that the Mammal class correctly defines the findSalmon() method. Which two changes allow this code to compile correctly?()
第3题:
Given the command line java Pass2 and: public class Pass2 { public void main(String [] args) { int x=6; Pass2 p = new Pass2(); p.doStuff(x); System.out.print(” main x = “+ x); } void doStuff(int x) { System.out.print(” doStuffx = “+ x++); } } What is the result?()
第4题:
Given the following code: 1) class Parent { 2) private String name; 3) public Parent(){} 4) } 5) public class Child extends Parent { 6) private String department; 7) public Child() {} 8) public String getValue(){ return name; } 9) public static void main(String arg[]) { 10) Parent p = new Parent(); 11) } 12) } Which line will cause error?()
第5题:
10. class Line { 11. public class Point { public int x,y; } 12. public Point getPoint() { return new Point(); } 13. } 14. class Triangle { 15. public Triangle() { 16. // insert code here 17. } 18. } Which code, inserted at line 16, correctly retrieves a local instance of a Point object?()
第6题:
doStuff x = 6 main x = 6
Compilation fails.
doStuff x = 6 main x = 7
An exception is thrown at runtime.
doStuff x = 7 main x = 6
doStuff x = 7 main x = 7
第7题:
Compilation fails.
An exception is thrown at runtime.
doStuffx=6 main x=6
doStuffx=6 mainx =7
doStuffx=7 mainx =6
doStuffx=7 mainx =7
第8题:
第9题:
Point p = Line.getPoint();
Line.Point p = Line.getPoint();
Point p = (new Line()).getPoint();
Line.Point p = (new Line()).getPoint();
第10题:
Point p = new Point();
Line.Point p = new Line.Point();
The Point class cannot be instatiated at line 15.
Line l = new Line() ; l.Point p = new l.Point();
第11题:
java Commander
java com. sim. sjcp.Commander
java com/sun/sjcp/Commander
java -cp com.sun.sjcp Commander
java -cp com/sun/sjcp Commander
第12题:
Java Test 2222
Java Test 1 2 3 4
Java Test 4 2 4 2
Java Test 4 3 2 1
第13题:
package com.sun.sjcp; public class Commander{ public static void main(String[]args){ //more code here } } Assume that the class fileis located in /foo/com/sun/sjcp/,the current directory is/foo/,and that the classpath contains“.“(current directory). Which command line correctly runs Commander?()
第14题:
10. class Line { 11. public static class Point { } 12. } 13. 14. class Triangle { 15. // insert code here 16. } Which code, inserted at line 15, creates an instance of the Point class defined in Line?()
第15题:
Given a correctly compiled class whose source code is: package com.sun.sjcp; public class Commander { public static void main(String[] args) { // more code here } } Assume that the class file is located in /foo/com/sun/sjcp/, the current directory is /foo/, and that the classpath contains “.“ (current directory). Which command line correctly runs Commander?()
第16题:
package foo; import java.util.Vector; private class MyVector extends Vector { int i = 1; public MyVector() { i = 2; } } public class MyNewVector extends MyVector { public MyNewVector () { i = 4; } public static void main (String args ) { MyVector v = new MyNewVector(); } } The file MyNewVector.java is shown in the exhibit. What is the result?()
第17题:
Given the following directory structure: bigProject |--source | |--Utils.java | |--classes |-- And the following command line invocation: javac -d classes source/Utils.java Assume the current directory is bigProject,what is the result? ()
第18题:
Java Test 2222
Java Test 1 2 3 4
Java Test 4 2 4 2
Java Test 4 3 2 1
第19题:
Compilation will succeed.
Compilation will fail at line 5.
Compilation will fail at line 6.
Compilation will fail at line 14.
Compilation will fail at line 17.
第20题:
args.count
args.length
args.count()
args.length()
args.getLength()
第21题:
If the compile is successful, Utils.class is added to the source directory.
The compiler returns an invalid flag error.
If the compile is successful, Utils.class is added to the classes directory.
If the compile is successful, Utils.class is added to the bigProject directory.
第22题:
line 3
line 6
line 7
line 8
line 10
第23题:
true
false
Compilation fails.
An exception is thrown at runtime.
第24题:
Compilation fails.
An exception is thrown at runtime.
doStuffx = 6 main x = 6
doStuffx = 6 main x = 7
doStuffx = 7 main x = 6
doStuffx = 7 main x = 7