diff --git a/Miscellaneous/Cpp/Pointer_to_object.java b/Miscellaneous/Cpp/Pointer_to_object.java new file mode 100644 index 0000000..3aaa764 --- /dev/null +++ b/Miscellaneous/Cpp/Pointer_to_object.java @@ -0,0 +1,28 @@ +package Cpp; + +class P_example { + private int num; + + void set_num(int val) { + num = val; + } + + void show_num() { + System.out.println(num); + } +} + +public class Pointer_to_object { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + P_example objectives[] = new P_example[2]; + objectives[0].set_num(10); + objectives[1].set_num(20); + + objectives[0].show_num(); + + } + +} diff --git a/Miscellaneous/Cpp/Pointer_to_object2.java b/Miscellaneous/Cpp/Pointer_to_object2.java new file mode 100644 index 0000000..8784043 --- /dev/null +++ b/Miscellaneous/Cpp/Pointer_to_object2.java @@ -0,0 +1,30 @@ +package Cpp; + +class P_example2{ + private int num; + + void set_num(int val) { + num = val; + } + + void show_num() { + System.out.println(num); + } +} + +public class Pointer_to_object2 { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + int[] array_of_integer = new int[5]; + + P_example2[] objectives = new P_example2[2]; + + objectives[0] = new P_example2(); + objectives[0].set_num(10); + objectives[0].show_num(); + + } + +} diff --git a/Miscellaneous/Cpp/Pointer_to_object3.java b/Miscellaneous/Cpp/Pointer_to_object3.java new file mode 100644 index 0000000..416dfa4 --- /dev/null +++ b/Miscellaneous/Cpp/Pointer_to_object3.java @@ -0,0 +1,30 @@ +package Cpp; + +class P_example3{ + private int num; + + void set_num(int val) { + num = val; + } + + void show_num() { + System.out.println(num); + } +} + +public class Pointer_to_object3 { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + P_example3 objective[] = {new P_example3(), new P_example3()}; + + objective[0].set_num(10); + objective[0].show_num(); + + objective[1].set_num(20); + objective[1].show_num(); + + } + +}