Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Mock Green Exam1 Question clarification  RSS feed

 
sabapathy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question asked in Mock Green -Exam1. I thought of working out this question but it is giving error as Type expected.
Can you tell anyone why this error i am getting. Thanks.
class sub
{
int i=9;
switch(i)
{
dafault:
System.out.println("deafult");
case 0:
System.out.println("one");
break;
case 1:
System.out.println("two");
}
}
 
Aru Ven
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sabapathy....
ur switch code is dangling.......try putting it in the main method or in any other method & then call that method....
Aruna
 
sabapathy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry i missed main method.After i have added main method i am getting a different error like "sub.java:9:Statement not reached.
But if i put a default block after case 1 it is not giving any error. Why? Can you explain me thanks.

class sub
{
public static void main(String args[])
{
int i=9;
switch(i)
{
dafault:
System.out.println("deafult");
case 0:
System.out.println("one");
break;
case 1:
System.out.println("two");
}
}
}
 
Anna s Iyer
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the spelling.
Anna S Iyer.
 
sabapathy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh man that was a silly mistake.
Thanks anna...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!