• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Return Type required

 
PETER CARTER
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. public class Alpha{
2. private static Character() ids;
3.
4. public static void main( String[] args){
4. ids = new Character[args.length];
5. for (int i=0; i<ids.length; i++){
6. ids[i] = new Character( args[i] );
7. System.out.print( ids[i] );
8. }
9. }
10. }
What is correct?
A. Compilation fails.
B. The code runs with no output.
C. An exception is thrown at runtime.
D. The code runs, outputing a concatenated list of the arguments passed to the program.
Answer: A
Explanation: Compilation fails. Line 2: Return Type required
Why ??
Thanks !!
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does this mean to you? Is it a method or what?
[ September 15, 2004: Message edited by: Barry Gaunt ]
 
s choukse
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Buddy, either you need to type the questions correct or please specify the source. Most important please try the questions yourself before you post on the ranch.. atleast run the code once.
 
Jeff Lloyd
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Presumably the round brackets on line 2 make the compiler think you are trying to declare a public static method which would require a return type that is missing. If the brackets were [] then you're declaring an array variable and the compiler is happy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic