-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create oops_classes_and_objects_basics.java
- Loading branch information
1 parent
6e7eea4
commit 6e4af16
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import java.util.*; | ||
public class Program | ||
{ | ||
public static class Person | ||
{ | ||
int age; | ||
String name; | ||
void sayHi() | ||
{ | ||
System.out.println(name+" ["+age+"] says hi"); | ||
} | ||
} | ||
public static void main(String[] args) | ||
{ | ||
Person p1=new Person(); | ||
p1.age=19; | ||
p1.name="Jiya"; | ||
p1.sayHi(); | ||
|
||
Person p2=new Person(); | ||
p2.age=23; | ||
p2.name="Yash"; | ||
p2.sayHi(); | ||
|
||
Person p3=p1; | ||
//here the address values of p1 is assigned to p3 | ||
p3.age=20; | ||
p3.sayHi(); | ||
p1.sayHi(); | ||
//here the modified changes in p3 also changes in p1 as the changes are made in the address | ||
} | ||
} |