-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_ClassObjects.java
More file actions
60 lines (44 loc) · 1.33 KB
/
Test_ClassObjects.java
File metadata and controls
60 lines (44 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.May2023;
public class Test_ClassObjects extends Parent13
{
/*Test_ClassObjects()
{
System.out.println("child class constructor");
}*/
Test_ClassObjects(String str)
{
super(str);
}
String car = "Ford" ;
public void testObj()
{
System.out.println("Print car name:- "+car);
}
//Re-assignment of object reference variables
public static void main(String[] args)
{
Test_ClassObjects object1 = new Test_ClassObjects("ty");
Test_ClassObjects object2 = object1 ;
Test_ClassObjects object3 = new Test_ClassObjects("yu");
//Both references - object1 and object2 are pointing to the same object.
object1.testObj();
object2.testObj();
//Change variable for object1 to "BMW"
object1.car = "BMW";
System.out.println("object1.car: "+object1.car);
System.out.println("object2.car: "+object2.car);
System.out.println("object3.car: "+object3.car);
//object1 ref is pointing to null , hence any operations performed on this object will throw a NullPointerException
object1 = null ;
System.out.println("object1.car: "+object1.car);
System.out.println("object2.car: "+object2.car);
System.out.println("object3.car: "+object3.car);
}
}
class Parent13
{
Parent13(String str)
{
System.out.println("Parent");
}
}