public class ItemTest {
private final mt id;
public ItemTest(int id) { this.id = id; }
public void updateId(int newId) { id = newId; }
public static void main(String[] args) {
ItemTest fa = new ItemTest(42);
fa.updateId(69);
System.out.println(fa.id);
}
}
What is the result?()
A. Compilation fails.
B. An exception is thrown at runtime.
C. The attribute id in the Item object remains unchanged.
D. The attribute id in the Item object is modified to the new value.
E. A new Item object is created with the preferred value in the id attribute.
您可能感兴趣的试卷
你可能感兴趣的试题
public class Item {
private String desc;
public String getDescription() { return desc; }
public void setDescription(String d) { desc = d; }
public static void modifyDesc(Item item, String desc) {
item = new Item();
item.setDescription(desc);
}
public static void main(String[] args) {
Item it = new Item();
it.setDescription(”Gobstopper”);
Item it2 = new Item();
it2.setDescription(”Fizzylifting”);
modifyDesc(it, “Scrumdiddlyumptious”);
System.out.println(it.getDescription());
System.out.println(it2.getDescription());
}
}
What is the outcome of the code? ()
A. Compilation fails.
B. Gobstopper Fizzylifting
C. Gobstopper Scrumdiddlyumptious
D. Scrumdiddlyumptious Fizzylifltng
E. Scrumdiddlyumptious Scrumdiddlyumptious
11. class Payload {
12. private int weight;
13. public Payload(int wt) { weight = wt; }
13. public void setWeight(mt w) { weight = w; }
15. public String toString { return Integer.toString(weight); }
16. }
17.
18. public class TestPayload {
19. static void changePayload(Payload p) {
20. /* insert code here */
21. }
22.
23. public static void main(String[] args) {
24. Payload p = new Payload();
25. p.setWeight(1024);
26. changePayload(p);
27. System.out.println(”The value of p is “+ p);
28. }
29. }
Which statement, placed at line 20, causes the code to print “The value of p is 420.”?()
A. p.setWeight(420);
B. p.changePayload(420);
C. p = new Payload(420);
D. Payload.setWeight(420);
E. p = Payload.setWeight(420);
F. p = new Payload(); p.setWeight(420);
11. public class Commander {
12. public static void main(String[] args) {
13. String myProp = /* insert code here */
14. System.out.println(myProp);
15. }
16. }
and the command line:
java -Dprop.custom=gobstopper Commander
Which two, placed on line 13, will produce the output gobstopper?()
A. System.load(”prop.custom”);
B. System.getenv(”prop.custom”);
C. System.property(”prop.custom”);
D. System.getProperty(”prop.custom”);
E. System.getProperties().getProperty(”prop.custom”);
public class Yippee2 {
static public void main(String [] yahoo) {
for(int x= 1; x
}
}
}
and the command line invocation: java Yippee2 a b c What is the result?()
A.a b
B.b c
C.a b c
D. Compilation fails.
E. An exception is thrown at runtime.
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.
最新试题
Which statement is true?()
Which statement is true about the set variable on line 12?()
A programmer iterates over the TreeSet and prints the name of each Drink object. What is the result?()
Which two can be results?()
Which statement is true?()
Which statement is true?()
What is the result?()
Which three will compile and run without exception?()
Which two of statements are true?()
What is the result?()