Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Guys Help me Out

 
deepu Bhalotia
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class JSC201 {
static byte m1() {
final char c1 = '\u0001';
return c1; // 1
}
static byte m2(final char c2) {return c2;} // 2
public static void main(String[] args) {
char c3 = '\u0003';
System.out.print(""+m1()+m2(c3)); // 3
}}


help me out in Solving this Question
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI

final char c1 = '\u0001';

now the value of c cannot be changed there after.
and determined at the time of compilation itself.
so byte b=c;
is same as byte b=1;
and no problem.

but

byte m2(final char c2) {return c2;}
the argument may be anything .
even it may exceed the range of byte.
and cannot be converted into byte implicitly.
so compilation error.
 
deepu Bhalotia
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Vidya....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic