This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt on Operators and Assignments 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 "Doubt on Operators and Assignments" Watch "Doubt on Operators and Assignments" New topic

Doubt on Operators and Assignments

Sneha Neil

Joined: May 31, 2004
Posts: 5
This question is from Dan Chislom's site:

class GFC100 {
public static void main(String[] args) {
final short s1 = 1; // 1
final char c1 = 1; // 2
byte b1 = s1; // 3
byte b2 = c1; // 4
byte b3 = 1; // 5
byte b4 = 1L; // 6
byte b5 = 1.0; // 7
byte b6 = 1.0d; // 8

I can understand the loss of precision errors for b4,b5 and b6.What I don't understand is why there are no such errors for b1 and b2? But, I get such an error when the final keyword is removed form s1 and c1. Can somebody please help me on this?

Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
You may find that Dan Chisholm's reponse in this recent post helps.

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

Joined: May 31, 2004
Posts: 5
Thanx a lot
Have you checked out Aspose?
subject: Doubt on Operators and Assignments
It's not a secret anymore!