• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

dif. bt. jdk2 and 3

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
public class A
{
public static void main(String[] args)
{
byte x=2;
switch(x)
{
case 'b': //1 // Here should be the problem.
default : // 2
case -2: // 3
case 80: // 4
}

}
}
// As we need casting 2 convert byte to char or char to byte,
//I thought that Line 1 should give error.But,it is not giving any error.
//Line //1 does not compile on JDK1.2 but it does work on 1.3!...why??

another problem:
-----
System.out.println(null + true); //1
System.out.println(true + null); //2
System.out.println(null + null); //3

Line //1 and //2 and //3 will not compile on JDK1.2 but work on 1.3!
NOw..My q. is what should be the answer in the real Exam for the above two ?
If they give 2 options like:
a. It will Compile.
b.It will not compile.
should I say a or b !!!


THANKS IN ADVANCE.
Ratul Banerjee

 
ratul banji
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pls...some1..tell me something
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ratul,
as for ur first ques, the code compiles on jdk 1.2 without any error.u have written the same but what do u mean by this line
//Line //1 does not compile on JDK1.2 .doesn't it seem quite contradictory?
for ur second ques the answer should be
b)It will not compile.
since u are giving SCJP2.
rajashree.
 
ratul banji
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks rajashree.
BTW..for the 1st one I mean 2 say that that code is working on jdk 3 only.
Thanks.
Ratul
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This compiles fine in 1.2.1. Perhaps you are not showing it correctly???
 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right Cindy,
The code works fine at my end too.
Ratul could you please resend the code so that we can have
look at it.
Rgds,
Ravi.
 
ratul banji
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,
YES, code 1 is working in jdk 1.2.
and Sorry for this...But , this is not (all) my fault.
Accually , the 1st one is 4rm JQPLUS.

Real question:
---------------
(Question ID :958057127800)
The following method will compile and run without any problems.
public void switchTest(byte x)
{
switch(x)
{
case 'b': // 1
default : // 2
case -2: // 3
case 80: // 4
}
}
a. True.
b. False.
And here is the Explanation given:
-----------------------------------
The following types can be used as a switch variables:
byte, char short and int. Note that, long float double and boolean are not allowed.
All the case constants should be assignable to the switch variable type.
Here, 'a' is assignable to x. Had there been a case label of 128, it would not have compiled. Because the range of a byte is from -128 to 127.
Line //1 does not compile on JDK1.2 but it does work on 1.3! As per specifications it should work.
Thanks.
Ratul Banerjee
reply
    Bookmark Topic Watch Topic
  • New Topic