Java automatic Packaging

Source: Internet
Author: User

The Java basic type has a package class, so that you can create a non-basic object in the heap to indicate the corresponding basic type.

Java's automatic packaging function is to automatically convert the basic type to the packaging type, and can reverse conversion.

Exercise: WriteProgramTo verify that the automatic packaging function works for all basic types and package types.

Exercise 9: (2) write a program that demonstrates that autoboxing works for all the primitive types and their wrappers.

 public class autoboxtest {public static void main (string [] ARGs) {Boolean B = false; char c = 'X '; byte T = 8; short S = 16; int I = 32; long l = 64; float F = 0.32f; double D = 0.64; Boolean B = B; system. out. println ("Boolean B =" + B); system. out. println ("Boolean B =" + B); character C = C; system. out. println ("char c =" + C); system. out. println ("character c =" + C); byte T = T; system. out. println ("Byte T =" + T); system. out. println ("Byte T =" + T); short S = s; system. out. println ("short S =" + S); system. out. println ("short S =" + S); integer I = I; system. out. println ("int I =" + I); system. out. println ("integer I =" + I); long l = L; system. out. println ("Long L =" + l); system. out. println ("Long L =" + l); float F = f; system. out. println ("float F =" + F); system. out. println ("float F =" + F); double D = D; system. out. println ("Double D =" + d); system. out. println ("Double D =" + d) ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.