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. an array
B. a heap
C. a stack
D. storage area
查看答案
Java allows you to declare methods with the same name in a class. This is called ________.
A. method redeclaration
B. method overloading
C. method overriding
D. method duplication
Analyze the following code: public class Test {public static void main(String[] args) {System.out.println(xMethod(5, 500L));} public static int xMethod(int n, long l) {System.out.println("int, long");return n;} public static long xMethod(long n, long l) {System.out.println("long, long");return n;} }
A. The program does not compile because the compiler cannot distinguish which xmethod to invoke.
B. The program runs fine but displays things other than 5.
C. The program displays long, long followed by 5.
D. The program displays int, long followed by 5.
Analyze the following code: class Test {public static void main(String[] args) {System.out.println(xmethod(5));} public static int xmethod(int n, long t) {System.out.println("int");return n;} public static long xmethod(long n) {System.out.println("long");return n;} }
A. The program displays long followed by 5.
B. The program displays int followed by 5.
C. The program does not compile because the compiler cannot distinguish which xmethod to invoke.
D. The program runs fine but displays things other than 5.
Analyze the following code. public class Test {public static void main(String[] args){System.out.println(m(2));} public static int m(int num) {return num;}public static void m(int num) {System.out.println(num);} }
A. The program runs and prints 2 twice.
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 has a compile error because the second m method is defined, but not invoked in the main methoD.