public class Yippee {
public static void main(String [] args) {
for(int x = 1; x < args.length; x++) {
System.out.print(args[x] +“ “);
}
}
}
and two separate command line invocations:
java Yippee
java Yippee 1234
What is the result?()
A. No output is produced. 123
B. No output is produced. 234
C. No output is produced. 1234
D. An exception is thrown at runtime. 123
E. An exception is thrown at runtime. 234
F. An exception is thrown at rijntime. 1234
您可能感兴趣的试卷
你可能感兴趣的试题
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?()
A. Compilation fails.
B. An exception is thrown at runtime.
C. doStuffx = 6 main x = 6
D. doStuffx = 6 main x = 7
E. doStuffx = 7 main x = 6
F. doStuffx = 7 main x = 7
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?()
A. java Commander
B. java com. sim. sjcp.Commander
C. java com/sun/sjcp/Commander
D. java -cp com.sun.sjcp Commander
E. java -cp com/sun/sjcp Commander
11. public class Counter {
12. public static void main(String[] args) {
13. int numArgs = /* insert code here */;
14. }
15. }
and the command line: java Counter one fred 42 Which code, inserted at line 13, captures the number of arguments passed into the program?()
A. args.count
B. args.length
C. args.count()
D. args.length()
E. args.getLength()
1. interface DoStuff2 {
2. float getRange(int low, int high); }
3.
4. interface DoMore {
5. float getAvg(int a, int b, int c); }
6.
7. abstract class DoAbstract implements DoStuff2, DoMore { }
8.
9. class DoStuff implements DoStuff2 {
10. public float getRange(int x, int y) { return 3.14f; } }
11.
12. interface DoAll extends DoMore {
13. float getAvg(int a, int b, int c, int d); }
What is the result?()
A. The file will compile without error.
B. Compilation fails. Only line 7 contains an error.
C. Compilation fails. Only line 12 contains an error.
D. Compilation fails. Only line 13 contains an error.
E. Compilation fails. Only lines 7 and 12 contain errors.
F. Compilation fails. Only lines 7 and 13 contain errors.
G. Compilation fails. Lines 7, 12, and 13 contain errors.
interface DeclareStuff{
public static final int EASY = 3;
void doStuff(int t); }
public class TestDeclare implements DeclareStuff {
public static void main(String [] args) {
int x=5;
new TestDeclare().doStuff(++x);
}
void doStuff(int s) {
s += EASY + ++s;
System.out.println(”s “ + s);
}
}
What is the result?()
A. s 14
B. s 16
C. s 10
D. Compilation fails.
E. An exception is thrown at runtime.
Given a class Repetition:
1. package utils;
2.
3. public class Repetition {
4. public static String twice(String s) { return s + s; }
5. }
and given another class Demo:
1. // insert code here
2.
3. public class Demo {
4. public static void main(String[] args) {
5. System.out.println(twice(”pizza”));
6. }
7. }
Which code should be inserted at line 1 of Demo.java to compile and run Demo to print“pizzapizza”?()
A. import utils.*;
B. static import utils.*;
C. import utils.Repetition.*;
D. static import utils.Repetition. *;
E. import utils.Repetition.twice();
F. import static utils.Repetition.twice;
G. static import utils.Repetition.twice;
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?()
A. add public to the start of line 4 in Salmon.java
B. add public to the start of line 4 in GrizzlyBear.java
C. add import animals.mammals.*; at line 2 in Salmon.java
D. add import animals.fish.*; at line 2 in GrizzlyBear.java
E. add import animals.fish.Salmon.*; at line 2 in GrizzlyBear.java
F. add import animals.mammals.GrizzlyBear.*;at line 2 in Salmon.java
Given classes defined in two different files:
1. package util;
2. public class BitUtils {
3. private static void process(byte[] b) { }
4. }
1. package app;
2. public class SomeApp {
3. public static void main(String[] args) {
4. byte[] bytes = new byte[256];
5. // insert code here
6. }
7. }
What is required at line 5 in class SomeApp to use the process method of BitUtils?()
A. process(bytes);
B. BitUtils.process(bytes);
C. app.BitUtils.process(bytes);
D. util.BitUtils.process(bytes);
E. import util.BitUtils. *; process(bytes);
F. SomeApp cannot use the process method in BitUtils.
Given classes defined in two different files:
1. package util;
2. public class BitUtils {
3. private static void process(byte[] b) { }
4. }
1. package app;
2. public class SomeApp {
3. public static void main(String[] args) {
4. byte[] bytes = new byte[256];
5. // insert code here
6. }
7. }
What is required at line 5 in class SomeApp to use the process method of BitUtils?()
A. process(bytes);
B. BitUtils.process(bytes);
C. app.BitUtils.process(bytes);
D. util.BitUtils.process(bytes);
E. import util.BitUtils. *; process(bytes);
F. SomeApp cannot use the process method in BitUtils.
Given classes defined in two different files:
1. package util;
2. public class BitUtils {
3. public static void process(byte[]) { /* more code here */ }
4. }
1. package app;
2. public class SomeApp {
3. public static void main(String[] args) {
4. byte[] bytes = new byte[256];
5. // insert code here
6. }
7. }
What is required at line 5 in class SomeApp to use the process method of BitUtils?()
A. process(bytes);
B. BitUtils.process(bytes);
C. util.BitUtils.process(bytes);
D. SomeApp cannot use methods in BitUtils.
E. import util.BitUtils.*; process(bytes);
最新试题
Which two are possible results?()
A programmer must create a generic class MinMax and the type parameter of MinMax must implement Comparable. Which implementation of MinMax will compile?()
Which three will compile and run without exception?()
What is the result?()
What is the result?()
Which statement is true?()
Which two of statements are true?()
What can be a result?()
What is the result?()
Which statement is true about the set variable on line 12?()