java第五章

绝世美人儿
533次浏览
2020年07月30日 16:17
最佳经验
本文由作者推荐

手的英语怎么写-审阅的近义词

1. Each time a method is invoked, the system stores parameters and local variables in an area of memory, known as _______, which stores elements in last-in first-out fashion.

a. a heap
b. an array
c. a stack
d. storage area

#
2. tWhat is (3.6)?

a. t3.0
b. t4
c. t5.0
d. t3

#
3. Which of the following is the best for generating random integer 0 or 1?

a. (int)() + 1
b. (int)()
c. (int)(() + 0.5)
d. (int)(() + 0.8)
e. (int)(() + 0.2)

#
4. tYou can define two methods in the same class with the same name and parameter list.

a. false
b. true

#
5. tThe signature of a method consists of the method name, parameter list and return type.

a. true
b. false

#
6. Given the following method

static void nPrint(String message, int n) {
while (n > 0) {
(message);
n--;
}
}

What is k after invoking nPrint("A message", k)?

int k = 2;
nPrint("A message", k);

a. t0
b. t3
c. t1
d. t2

#
7. tWhich of the following method results in 8.0?

a. (8.5)
b. (8.5)
c. (8.5)
d. (8.5)

#
8. tArguments to methods always appear within __________.

a. tparentheses
b. tquotation marks
c. tcurly braces
d. tbrackets

#
9. __________ is a simple but incomplete version of a method.
a. A stub
b. A method developed using top-down approach
c. A non-main method
d. A main method

#
10. tYou must have a return statement in a non-void method.

a. true
b. false

#
11. Methods can be declared in any order in a class.

a. false
b. true

#
12. tWhat is k after the following block executes?
{
int k = 2;
nPrint("A message", k);
}
n(k);


a. t0
b. tk is not defined outside the block. So, the program has a compile error
c. t2
d. t1

#
13. tDoes the method call in the following method cause compile errors?

public static void main(String[] args) {
(2, 4);
}

a. tNo
b. tYes

#
14. (int)('a' + () * ('z' - 'a' + 1)) returns a random number __________.

a. between 'a' and 'y'
b. between (int)'a' and (int)'z'
c. between 'a' and 'z'
d. between 0 and (int)'z'

#
15. A return statement without any value can be used in _______.

a. ta non-void method
b. tvoid method

#
16. tAll Java applications must have a method __________.

a. public static main(String[] args)
b. tpublic static Main(String[] args)
c. tpublic static void main(String[] args)
d. tpublic void main(String[] args)
e. tpublic static Main(String args[])

#
17. tWhich of the following is not an advantage of using methods.

a. tUsing methods makes programs easier to read.
b. tUsing methods makes reusing code easier.
c. tUsing methods hides detailed implementation from the clients.
d. tUsing methods makes programs run faster.

#
18. tWhat is ( / 2)?

a.
1.5
b. t0.5
c. 1.0
d. t1
e. t0.4

#
19. A variable defined inside a method is referred to as __________.

a. a method variable
b. a local variable
c. a global variable
d. a block variable

#
20. tWhat is (3.6)?

a. t3.0
b. t4.0
c. t4
d. t3

#
21. tWhat is (int)()?

a. t0.5
b. t1.1
c. t1
d. t0

#
22. The modifiers and return value type do not contribute toward distinguishing one method from another, only the parameter list.

a. false
b. true

#
23. A call for the method with a void return type is always a statement itself, but a call for the method with a non-void return type can be treated as either a statement or an expression.

a. true
b. false

#
24. You should fill in the blank in the following code with ______________.

public class Test {
public static void main(String[] args) {
("The grade is " + getGrade(78.5));
("
The grade is " + getGrade(59.5));
}

public static _________ getGrade(double score) {
if (score >= 90.0)
return 'A';
else if (score >= 80.0)
return 'B';
else if (score >= 70.0)
return 'C';
else if (score >= 60.0)
return 'D';
else
return 'F';
}
}


a. char
b. void
c. boolean
d. int
e. double

#
25. Consider the following incomplete code:

public class Test {
public static void main(String[] args) {
n(f(5));
}

public static int f(int number) {
// Missing body
}
}

The missing method body should be ________.

a. n(number);
b. n("number");
c. return "number";
d. return number;

#
26. tWhat is (3.6)?

a. t4.0
b. t3.0
c. t3
d. t5.0

#
27. Variables defined inside a method are called _____.

a. tlocal variables
b. tparameters
c. targuments
d. tglobal variables

#
28. The client can use a method without knowing how it is implemented. The details of the implementation are encapsulated in the method and hidden from the client who invokes the method. This is known as __________.

a. method hiding
b. simplifying method
c. encapsulation
d. information hiding

#
29. Analyze the following code.

public class Test {
public static void main(String[] args) {
n(m(2));
}

public static int m(int num) {
return num;
}

public static void m(int num) {
n(num);
}
}

a. The program has a compile error because the second m method is defined, but not invoked in the main method.
b. The program has a compile error because the two methods m have the same signature.
c. The program runs and prints 2 once.
d. The program runs and prints 2 twice.

#
30. Analyze the following code:

public class Test {
public s
tatic void main(String[] args) {
n(xMethod(5, 500L));
}

public static int xMethod(int n, long l) {
n("int, long");
return n;
}

public static long xMethod(long n, long l) {
n("long, long");
return n;
}
}

a. tThe program displays long, long followed by 5.
b. tThe program runs fine but displays things other than 5.
c. tThe program displays int, long followed by 5.
d. tThe program does not compile because the compiler cannot distinguish which xmethod to invoke.

#
31. tWhat is ((3, 6), 2)?

a. t2.0
b. t3
c. 3.0
d. t2
e. t4

#
32. A _____ method does not return a value.

a. tvoid
b. tnon-void

#
33. Variables defined in the method header are called _____.

a. tlocal variables
b. tparameters
c. tglobal variables
d. targuments

#
34. Java allows you to declare methods with the same name in a class. This is called ________.

a. tmethod duplication
b. tmethod overloading
c. tmethod redeclaration
d. tmethod overriding

#
35. (5.5) evaluates to _____.

a. 6.0
b. 6
c. 5.0
d. 5

#
36. __________ is to implement one method in the structure chart at a time from the top to the bottom.

a. Top-down approach
b. Bottom-up and top-down approach
c. Stepwise refinement
d. Bottom-up approach

#
37. (3, 3) returns _______.

a. t27
b. 9.0
c. t9
d. 27.0

#
38. tYou may have a return statement in a void method.

a. true
b. false

#
39. tEach Java class must contain a main method.

a. ttrue
b. tfalse

#
40. tDoes the return statement in the following method cause compile errors?

public static void main(String[] args) {
int max = 0;
if (max != 0)
n(max);
else
return;
}

a. tYes
b. tNo

#
41. tWhich of the following is a possible output for (int)(51 * ())?

a. t100
b. t0
c. t500
d. t50

#
42. (4) returns _______.

a. 1
b. t2.0
c. t2
d. 1.0

#
43. tWhat is (3.6)?

a. t3.0
b. t4.0
c. t3
d. t5.0

#
44. tWhich of the following method returns the sine of 90 degree?

a. ()
b. (PI)
c. (90)
d. (an(90))
e. (90)

#
45. Suppose your method does not return any value, which of the following keywords can be used as a return type?

a. tint
b. tvoid
c. tNone of the above
d. tdouble
e. tpublic

#
46. tThe actual parameters of a method must match the formal parameters in type, order, and number.

a. false
b. true

#
47. tWhat is (0.5)?

a. / 6
b. t90
c. / 2
d. t30

#
48. tA method can be defined inside a method in Java.

a. true
b. false

#
49. Analyze the following code:

class Test {
public static void main(String[] args) {
n(xMethod((do
uble)5));
}

public static int xMethod(int n) {
n("int");
return n;
}

public static long xMethod(long n) {
n("long");
return n;
}
}


a. tThe program does not compile.
b. tThe program displays int followed by 5.
c. tThe program runs fine but displays things other than 5.
d. tThe program displays long followed by 5.

#
50. Given the following method

static void nPrint(String message, int n) {
while (n > 0) {
(message);
n--;
}
}

What is the printout of the call nPrint('aeter list

#
64. You should fill in the blank in the following code with ______________.

public class Test {
public static void main(String[] args) {
("The grade is ");
printGrade(78.5);

("The grade is ");
printGrade(59.5);
}

public static __________ printGrade(double score) {
if (score >= 90.0) {
n('A');
}
else if (score >= 80.0) {
n('B');
}
else if (score >= 70.0) {
n('C');
}
else if (score >= 60.0) {
n('D');
}
else {
n('F');
}
}
}



a. char
b. int
c. double
d. void
e. boolean

#
65. Which of the following should be defined as a void method?

a. Write a method that converts an uppercase letter to lowercase.
b. Write a method that checks whether current second is an integer from 1 to 100.
c. Write a method that prints integers from 1 to 100.
d. Write a method that returns a random integer from 1 to 100.

#
66. tYou can redeclare the variable if it is declared in the method signature.

a. false
b. true

#
67. (5.5) evaluates to _____.
a. 5
b. 6
c. 5.0
d. 6.0

#
68. tWhat is ( / 6)?

a. t1.5
b. t1
c. t0.5
d. t0.4

#
69. Analyze the following code.

public class Test {
public static void main(String[] args) {
n(max(1, 2));
}

public static double max(int num1, double num2) {
n("max(int, double) is invoked");

if (num1 > num2)
return num1;
else
return num2;
}

public static double max(double num1, int num2) {
n("max(double, int) is invoked");

if (num1 > num2)
return num1;
else
return num2;
}
}

a. The program cannot compile because the compiler cannot determine which max method should be invoked.
b. The program runs and prints 2 followed by "max(double, int)" is invoked.
c. The program cannot compile because you cannot have the print statement in a non-void method.
d. The program runs and prints 2 followed by "max(int, double)" is invoked.
e. The program runs and prints "max(int, double) is invoked" followed by 2.

与人无尤-阵雨的拼音


sdi是什么意思-碑帖读音


众成语-甜蜜的拼音


IQ是什么-弄瓦之喜是什么意思


ln的公式-什么欲滴


主从复合句-顷刻拼音


得意的反义词是什么-宽阔反义词


语文与生活-蕙心兰质