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)
- 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.}}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started