This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Primitive Casting Exercise

 
Jimmy Blakely
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found these questions over at JavaOnline.
I'm simply looking to confirm my answers for this exercise.

C A S T I N G
Question No : 1) In the following class definition, which is the first line (if any) that causes a compilation error. Select the one correct answer.
char c;
int i;
c = 'A';// 1
i = c;//2
c = i + 1;//3
c++;//4
A. The line labeled 1.
B. The line labeled 2.
C. The line labeled 3.
D. The line labeled 4.
E. All the lines are correct and the program compiles
Question 2) Which line in the following code will not compile
1. byte b=5;
2. char c='5';
3. short s=55;
4. int i=555;
5. float f=555.5f;
6. b=s;
7. i=c;
8. f=i;
Question 3) Will the following code compile ?
1. byte b=2;
2. byte b1=3;
3. b*=b1;
Question No.4)In the code below what are the possivle types for variable result ?
1. byte b=11;
2. short s=13;
3. result=b*s;
1) byte, short, int, long, float, double.
2) boolean, byte, short, char, int, long, float, double.
3) byte, short, char, int, long, float, double.
4) byte, short, char.
5) int, long, float, double.
_____________________________________________
Answers:
1) c
2) 6
3) Yes
4) 5
 
Gurpreet Sachdeva
Ranch Hand
Posts: 90
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Jimmy,
Your answers are correct.
Gurpreet Sachdeva
For mock exams and other useful pages(including topics like bitshift operator, garbage collection,inner classes,etc) please visit: http://www.go4java.20m.com
 
Ragu Sivaraman
Ranch Hand
Posts: 464
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Jimmy,
Answers are correct
Good job
 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abosulely correct shots with 500 mph speed and from 5 meter distances....
------------------
azaman
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic