About Question enthuware.ocpjp.v8.2.1667 :

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

Moderator: admin

Post Reply
jabenitez
Posts: 9
Joined: Tue Apr 17, 2018 5:03 am
Contact:

About Question enthuware.ocpjp.v8.2.1667 :

Post by jabenitez »

Hi everybody,

I have a question with

Code: Select all

public class TestClass {     
    public static void main(String[] args) {          
        int x = 1____3;   //1          
        long y = 1_3;     //2          
        float z = 3.234_567f; //3          
        System.out.println(x+" "+y+" "+z);     
    }
}
I understood that you should always put L or l when creating a long from a literal because by default the numerical literals (without decimal) are int.

When is necessary put L or l in literals to create long vars?

Thanks in advance.

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

Re: About Question enthuware.ocpjp.v8.2.1667 :

Post by admin »

You need to put L or l when the value of the literal that you want to write is too big to fit into an int. If you don't append L or l then the compiler will take it as an int and since the value is too big, it will complain that it is too big for an int.

FYI, you don't need to worry about the actual value after which you have to put an L to make it compile for the exam.
If you like our products and services, please help us by posting your review here.

jabenitez
Posts: 9
Joined: Tue Apr 17, 2018 5:03 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1667 :

Post by jabenitez »

admin wrote:You need to put L or l when the value of the literal that you want to write is too big to fit into an int. If you don't append L or l then the compiler will take it as an int and since the value is too big, it will complain that it is too big for an int.

FYI, you don't need to worry about the actual value after which you have to put an L to make it compile for the exam.
Ok, many thanks.


Regards,
Juan Antonio.

Post Reply

Who is online

Users browsing this forum: No registered users and 41 guests