The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes on compile time constant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "on compile time constant" Watch "on compile time constant" New topic

on compile time constant

velan vel
Ranch Hand

Joined: Nov 15, 2005
Posts: 137
hai ranchers here how is the ans is d
can any one explains

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

What is the result of attempting to compile and run the program?

a. Prints: 13
b. Prints: 4
c. Compile-time error at 1
d. Compile-time error at 2
e. Run-time error
f. None of the above

$ Velan Vel @ SCJP 1.4 $
You learn From Your Failures, Others Will Learn From Your Success
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
What does the compilation error tell you?

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
achayya matta
Ranch Hand

Joined: Oct 27, 2005
Posts: 111
hai vel

In method m2() the return type shoud not be either byte or short.
I agree. Here's the link:
subject: on compile time constant
It's not a secret anymore!