What is boxing and unboxing? - ICSE Java Expert

Breaking

ICSE Java Expert

Learn Java for school

Unordered List

WELCOME

Monday, August 06, 2018

What is boxing and unboxing?

Boxing and Un-Boxing

Well the term boxing with respect to Java does not mean to bout but it is related to opening a box to discover something new.
Boxing: Converting a value type data into a reference type data.
Un-boxing: Converting a reference type data into a value type data.

CASTING

For example:
int age = 12; // a variable age is declared with integer data type and assigned a value 12.
int vowel = 'e'; // in this line of code a variable vowel is declared and assigned a value 'e' but the datatype of the variable is int so the ASCII code of 'e' that is 101 will be assigned to the variable. This is the what we call as implicit casting because the value 'e' that is of char type implicitly castes into its corresponding ASCII code that is integer type.







No comments:

Post a Comment