A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Programmer Certification (SCJP/OCPJP)
What is the output for First Snippet and Second Snippet?
Joined: Jan 03, 2007
Jan 03, 2007 07:05:00
public static void main(
final int i = 100;
byte b = i;
public static void main(String args)
int i = 100;
byte b = i;
Joined: Mar 22, 2005
Jan 03, 2007 07:21:00
Welcome to JavaRanch.
That's quite easy to find out, isn't it?
Java web charts
Joined: Jun 29, 2006
Jan 03, 2007 09:26:00
The First Snippet will compile, run and print 100.
The second Snippet will not compile.
In the First Snippet, i is cmpile time constant and its value 100 is in the range of byte so no explicit casting is required.
In the Second Snippet, i is not compile time constant. So, you have to explicitly cast the value of integer i to byte.
byte b = (byte)i will work.
[ January 03, 2007: Message edited by: Neel Joshi ]
Joined: Feb 24, 2006
Jan 03, 2007 09:40:00
Is that a quiz or a question ?
SCJP 6 articles
SCJP 5/6 mock exams
SCJP 5 Mock exam (Word document )
SCJP 5 Mock exam in Java.Inquisition format
I agree. Here's the link:
- it saves me about five hours per week
subject: What is the output for First Snippet and Second Snippet?
Rule about final?
Can't figure please help!
automatic primitive conversion from higher to lower precision?????
how about this test?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013