Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

Define self-expectancy and explain two ways to boost it.

Answered: 1 week ago

Question

Describe the Betting-Against-Beta (BAB) strategy.

Answered: 1 week ago