About Question enthuware.ocajp.i.v8.2.1314 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
vilasa
Posts: 7
Joined: Tue Apr 16, 2019 5:40 pm
Contact:

About Question enthuware.ocajp.i.v8.2.1314 :

Post by vilasa »

One of the answer is Conversion from byte to short doesn't need a cast. I tried testing this.But it gives compiler error sayin incompatible types

byte by1=10;
s=by1;
error: incompatible types: byte cannot be converted to Short
s=by1;
^
1 error

Thanks,
Veena

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1314 :

Post by admin »

Please post the complete and exact code that you are trying to compile. From the error message, it looks like you are using Short instead of short.
If you like our products and services, please help us by posting your review here.

vilasa
Posts: 7
Joined: Tue Apr 16, 2019 5:40 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1314 :

Post by vilasa »

You are right. It was Short ,not short. Thank you.

girishankaran
Posts: 10
Joined: Wed Aug 08, 2012 5:00 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1314 :

Post by girishankaran »

Conversion from char to long does not need a cast. the answer is true or false?
Its shows true

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1314 :

Post by admin »

What happened when you tried it out?
If you like our products and services, please help us by posting your review here.

jeroenisanders
Posts: 6
Joined: Sun Feb 07, 2021 9:49 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1314 :

Post by jeroenisanders »

Conversion from int to float does need a cast. The opposite is not true. For instance next will not compile:
float fll = 1;
int int23 = 2;
int23 = fll;

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1314 :

Post by admin »

jeroenisanders wrote:
Sun Feb 07, 2021 11:12 am
Conversion from int to float does need a cast. The opposite is not true. For instance next will not compile:
float fll = 1;
int int23 = 2;
int23 = fll;
No, conversion from int to float DOES NOT need a cast. conversion from float to int needs a cast.
That is why, in your example, the first line compiles fine. The third line does not.
If you like our products and services, please help us by posting your review here.

herngyih
Posts: 6
Joined: Fri Jun 03, 2022 9:14 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1314 :

Post by herngyih »

"Conversion from short to char needs a cast". The reason given is because their ranges are not compatible. Both are 16 bits though.

1.Is it because char is unicode and short is integral?

2.Notice that byte is 8 bits and yet still need casting to fit into char(16 bits).Why?

Code: Select all

  	  byte bytey =1;
	  
	  char chary = 'a';
	  
	  chary =  bytey; //fail
	  
	  chary =  (char)bytey; //OK
	  
	  

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1314 :

Post by admin »

No, it is because short can have negative values while char cannot. byte, char, short, int , and long are all integral types.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests