What Is A Primitive What Is An Object - Pps
What Is A Primitive What Is An Object - Pps
What is a primitive?
What is an Object? What is a primitive?
int x; A primitive variable is NOT an object. It is stored in one
x = 2; place in RAM.
int x
2
What is an Object? What is a primitive?
String y;
A String is an object. Here, I have only declared a
reference. We say “’y’ is a reference to an object of
type String. However, at this point, ‘y’ points to
nothing.
String y
null
Now, using the new keyword to execute
What is an Object? What is a primitive?
the Constructor method, I have created
String y; an instance of the String class. Then, I
return the address (of the object I just
y = new String( “Hello” ); created) to the reference ‘y’, which then
points to the object. Now, ‘y’ points to the
object I just created.
String y
3433245
3433245
String “Hello”