Sy Java
Sy Java
Parameter of
Object Reference
Comparison
Basic definition It is the instance of a class and all the elements it A simply memory reference that points to where the
contains are based on the blueprint of the class. object is stored in memory slot.
Format for There is a simple format for creation of an object: The memory reference is created alongside object. It is
creation ClassName reference_variable = new used in the format for object creation and is given a
ClassName(with parameter); variable name
Elements It contains methods and variables based on the It contains a sequence of bits that store the address of
class. the object.
Mutable Objects have states and behaviors that can be The reference variable value cannot be changed. It can
changed, i.e, the state of the object can be only remain as the data type that it was declared as.
changed.
Virtual meaning It is a real world entity that holds some form of It is nothing but a variable name, which has no real
memory or data. meaning. It is like the name of a person, that references
that person.
class AutoboxingExample1
{
public static void myMethod(Integer num){
System.out.println(num);
}
public static void main(String[] args) {
/* passed int (primitive type), it would be
* converted to Integer object at Runtime
*/
myMethod(2);
}
}
Output:
2
Case 2: When at some point of time, you are assigning a primitive type value to an object of
its wrapper class. For example: The below statements are valid because compiler does the
autoboxing at runtime.
class UnboxingExample1
{
public static void myMethod(int num){
System.out.println(num);
}
public static void main(String[] args) {
100
Case 2: Assignments
13.
List and explain overloaded constructors of String class.
14.