2. Now lets access the instance variables in the above
Box class, by creating an object for the above
Box Class in another class called 'DotOperatorDemo' by following the next steps.
3. Create a new class named 'DotOperatorDemo' under 'Third Project' as shown below:
4. Create an object for the
Box class in
DotOperatorDemo class as shown below
5. Type box1 and type '.' as shown below and observe that instance variables declared in Box class will be displayed as shown below:
6. Select any one of the displayed instance variable say
depth and the selected instance variable will be added to your code as shown below:
7. Now assign a value to the inserted variable as shown below:
8. Now print the value of
box1.depth as shown below:
9. Save the
DotOperatorDemo class and Run it As -> Java application as shown below:
10. Observe that the value 100.0 got printed in console as shown below:
Download this program:
Click here to download the program which contains the
DotOperatorDemo class (After download, you can import this project to Eclipse IDE installed on your machine)