JAVA Chapter 6 Exam Questions
and Answers
Q1: Overloaded methods always have the same _________.
a. a. method name.
b. b. return type.
c. c. number of parameters.
d. d. order of the parameters. - Answer-ANS: a. method name.
Q2: An overloaded method is one that
a. a. has a different name than another method, but the same parameters.
b. b. has the same name as another method, but different parameters (by number,
types or order of the types).
c. c. has the same name and parameters as a method defined in another class.
d. d. has the same name and parameters, but a different return type as another method.
- Answer-ANS: b. has the same name as another method, but different parameters (by
number, types or order of the types).
Q3: Which of the following methods are overloaded with respect to one another?
public int max ( int a, int b ) { ... }
public double max ( double a, double b ) { ... }
public int max ( int a, int b, int c ) { ... }
public double max ( double a, double b, double c ) { ... }
a. a. A and B are overloaded; C and D are overloaded.
b. b. A and C are overloaded; B and D are overloaded.
c. c. A, B and C are overloaded.
d. d. All these four methods are overloaded. - Answer-ANS: d. All these four methods
are overloaded.
Q4: Suppose method1 is declared as
void method1 ( int a, float b )
Which of the following methods correctly overloads method1?
a. a. void method2 ( int a, float b ).
, b. b. void method2 ( float a, int b ).
c. c. void method1 ( float a, int b ).
d. d. void method1 ( int b, float a ). - Answer-ANS: c. void method1 ( float a, int b ).
Q5: A Java class can have which of the following methods?
A. A. void foo( int a )
B. B. void foo( int a, int b )
C. C. void foo( double a )
D. D. void foo( double a, double b )
E. E. void foo( int b )
a. a. All of the above.
b. b. A, B, D, E.
c. c. A, B, C, D.
d. d. A, C, D, E. - Answer-ANS: c. A, B, C, D.
Q6: Method calls cannot be distinguished by ________.
a. a. method name.
b. b. return type.
c. c. parameter lists.
d. d. method signature. - Answer-ANS: b. return type.
Q7: In a class containing methods with the same name, the methods are distinguished
by:
a. a. Number of arguments.
b. b. Types of arguments.
c. c. Return type.
d. d. (a) and (b).
e. e. (b) and (c). - Answer-ANS: d. (a) and (b).
Q1: Information is passed to a method in:
a. a. the method name.
b. b. that method's return.
c. c. the method body.
d. d. the arguments to the method. - Answer-ANS: d. the arguments to the method.
2 Q2: Programs designed for maintainability are constructed from small simple pieces
or modules. Modules in Java are called:
a. a. methods.
b. b. classes.
c. c. arguments.
d. d. both methods and classes. - Answer-ANS: d. both methods and classes
2 Q3: A well-designed method
and Answers
Q1: Overloaded methods always have the same _________.
a. a. method name.
b. b. return type.
c. c. number of parameters.
d. d. order of the parameters. - Answer-ANS: a. method name.
Q2: An overloaded method is one that
a. a. has a different name than another method, but the same parameters.
b. b. has the same name as another method, but different parameters (by number,
types or order of the types).
c. c. has the same name and parameters as a method defined in another class.
d. d. has the same name and parameters, but a different return type as another method.
- Answer-ANS: b. has the same name as another method, but different parameters (by
number, types or order of the types).
Q3: Which of the following methods are overloaded with respect to one another?
public int max ( int a, int b ) { ... }
public double max ( double a, double b ) { ... }
public int max ( int a, int b, int c ) { ... }
public double max ( double a, double b, double c ) { ... }
a. a. A and B are overloaded; C and D are overloaded.
b. b. A and C are overloaded; B and D are overloaded.
c. c. A, B and C are overloaded.
d. d. All these four methods are overloaded. - Answer-ANS: d. All these four methods
are overloaded.
Q4: Suppose method1 is declared as
void method1 ( int a, float b )
Which of the following methods correctly overloads method1?
a. a. void method2 ( int a, float b ).
, b. b. void method2 ( float a, int b ).
c. c. void method1 ( float a, int b ).
d. d. void method1 ( int b, float a ). - Answer-ANS: c. void method1 ( float a, int b ).
Q5: A Java class can have which of the following methods?
A. A. void foo( int a )
B. B. void foo( int a, int b )
C. C. void foo( double a )
D. D. void foo( double a, double b )
E. E. void foo( int b )
a. a. All of the above.
b. b. A, B, D, E.
c. c. A, B, C, D.
d. d. A, C, D, E. - Answer-ANS: c. A, B, C, D.
Q6: Method calls cannot be distinguished by ________.
a. a. method name.
b. b. return type.
c. c. parameter lists.
d. d. method signature. - Answer-ANS: b. return type.
Q7: In a class containing methods with the same name, the methods are distinguished
by:
a. a. Number of arguments.
b. b. Types of arguments.
c. c. Return type.
d. d. (a) and (b).
e. e. (b) and (c). - Answer-ANS: d. (a) and (b).
Q1: Information is passed to a method in:
a. a. the method name.
b. b. that method's return.
c. c. the method body.
d. d. the arguments to the method. - Answer-ANS: d. the arguments to the method.
2 Q2: Programs designed for maintainability are constructed from small simple pieces
or modules. Modules in Java are called:
a. a. methods.
b. b. classes.
c. c. arguments.
d. d. both methods and classes. - Answer-ANS: d. both methods and classes
2 Q3: A well-designed method