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

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)

  1. Print out num
  2. Change 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. Change main.num4 to 10
  7. Print out main2.num4
  8. Now change main2.num2 to 15
  9. 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.}}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!