• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

I cant believe the ans?

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
25. Given the variables defined below:
int one = 1;
int two = 2;
char initial = '2';
boolean flag = true;
Which of the following are valid?
a) if( one ){}
b) if( one = two ){}
c) if( one == two ){}
d) if( flag ){}
e) switch( one ){}
f) switch( flag ){}
g) switch( initial ){}

my ans to this question is:c,d,e,f,g
the clearly ans is not given it just dudge my ans :wrong.
I know the parameter apply the switch is string,boolean,char,int.
Do you think my ans is right?if not ,where is wrong?and what is the right answer?
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hii..
f) switch( flag ){} --> is invalid
For Switch Statement,the type of the Expression must be char, byte, short, or int, or a compiletime error occurs.(Java Language Specification 14.10)
chin
 
james gong
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all are correct except boolean, boolean is not allowed in switch.
 
Hey cool! They got a blimp! But I have a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic