Card 38 / 76: You want to create a method that takes in three character parameters and returns a string. Which declaration is valid?
A)
public void doMethod (char a, char b, char c) {String s = null; return s;}
B)
public String doMethod (Char a, Char b, Char c) {String s = null; return s;}
C)
public String doMethod (char a, char b, char c) {String s = null; return s;}
D)
public string doMethod (char a, char b, char c) {String s = null; return s;}
Answer:
C) public String doMethod (char a, char b, char c) {String s = null; return s;}
Previous Card | ← Previous Card Button |
Next Card | → Next Card Button |
Flip Card | Space-Bar |
A, B, and D are incorrect.
A is incorrect because the declaration states that no value (void) is to be returned, but a string is.
B is incorrect because the wrapper class for character is Character and not Char.
D is incorrect because the return type of String does not start with a capital letter as it should.
That is, "public string doMethod" should read "public String doMethod".
|