Description: This activity will help you understand about class scopes and class variables. Please follow the steps
Question:
Description:
This activity will help you understand about class scopes and class variables. Please follow the steps below:
Steps:
(See these instructions in Main.java as well)
- Print out num
- Change num2 to 10
- Show an instance of Main called main
- Print out main.num4
- Show a new Main object called main2
- Change main.num4 to 10
- Print out main2.num4
- Now change main2.num2 to 15
- Print out main.num2
class Main { // Class scope variablestatic int num = 5;// Class scope without initializationstatic int num2;// Class scope reference variable.static Main num3; // This is set to null since a value is not instantiated. /* Object scoped variable. Every Main object will have its own copy of this variable* that it can work with independently.* object scopes don't have the static keyword.*/double num4 = 1.23; public static void main(String[] args) { // 1. Print out the value of num without doing "5" or 5 // 2. Reassign num2 to 10 // 3. Show an instance of Main called main // 4. Print out main.num4 // 5. Show a new Main object called main2 // 6. Reassign main.num4 to 10 // 7. Print out main2.num4 // See how main2.num4 doesn't change when you change main.num4. // 8. Now reassign main2.num2 to 15 // 9. Print out main.num2 // See how when you change main2.num2 then main.num2 also changes. This is because num2 is a static variable.}}
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill