1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Marta_Voda [28]
3 years ago
10

How are static variables and methods created in Java? What happens if a non-static method of a class tries to access a static va

riable of that class? What happens to the static variables of a class once the class has no instances?
Computers and Technology
1 answer:
9966 [12]3 years ago
4 0

Answer:

Static variables are the variables decaraed with keyword static, static variables must be deacraled inside the class body, means we can not declare a static variable inside a method or consttructor, static variable belongs to class, for a class only one copy is created for static variable and used by all the objects/instances.

Static variable can access with class name like

X.i

Static method are the methods defined with static keyword, static method are also part of a class, we can access static meethod using class name like

X.printI()  

Explanation:

class X

{

//to create a static variable we need use static keyword with variable name like

public static int i;

// to create a static method we need to use static keyword while defining a method like

public static void printHello() {

 System.out.println("Hello");

}

/*

 * A non static method can access static variable of a class there is no issue

 * with that we can use a static variable in a non static method like

 */

public void printI() {

 System.out.println(i);

}

/*

 * As long as the class exist in JVM static variables will be there, as static

 * variable belong to class not with the instance,

 * it does not matters if there are instance exist or not

 */

}

You might be interested in
Which of the following actions taken by the Fed will increase the nation’s money supply? (Select all that apply.)
pashok25 [27]

Answer:

it is A.Lowering the reserve ratio

5 0
2 years ago
Suppose that the first goal in a GP problem is to make 3 X1 + 4 X2 approximately equal to 36. Using the deviational variables d1
Scrat [10]

Answer:

d. d1− = 10, d1+ = 0

Explanation:

Given

3X1 + 4X2 +d1− − d1+ = 36

X1 = 6

X2 = 2

Required

Possible values of d1- and d1+

We have:

3X1 + 4X2 +d1− − d1+ = 36

Substitute values for X1 and X2

3 *6 + 4 * 2 + d1- - d1+ = 36

18 + 8 + d1- - d1+ = 36

Collect like terms

d1- - d1+ = 36 - 18 - 8

d1- - d1+ = 10

For the above equation to be true, the following inequality must be true

d1- > d1+

Hence,

(d) is correct

Because:

10 > 0

3 0
2 years ago
C program how to input this? ​
Neporo4naja [7]
Chchvjvcuvggiiog. Correct
3 0
3 years ago
Write the function "zipper". the function will take two array/list/table parameters and return a new array/list/table which will
MakcuM [25]
What is the problem what am I supposed to do?
4 0
3 years ago
What is does ram means,??
jenyasd209 [6]
It means to roughly force something into place or an ungelded boy sheep XDDD
7 0
3 years ago
Read 2 more answers
Other questions:
  • What is the main storage device where the computer stores data?
    15·1 answer
  • why is it important to use a general search engine, like GOOGLE, to look up the name of the organization, institution, agency or
    7·1 answer
  • Which does the histogram resemble the most?
    10·1 answer
  • Header and Footer options are located in the _____ tab.
    7·1 answer
  • A page with no meaningful content that is full of ads and the webmaster makes money from if someone clicks on them is called____
    7·1 answer
  • Write a function named "higher_lower" that takes an int as a parameter and returns "higher" if 14 is greater than the input and
    11·1 answer
  • Select the correct answer.
    15·2 answers
  • Bonjour ma question est: expliquer comment fonctionne une calculatrice qui ne contient pas une pile. Pouvez-vous m'aider?
    12·1 answer
  • Write a program in python to make the figure:-
    12·1 answer
  • Question 1 Which portion of the PuTTY package allows you to perform file transfers using the SCP (Secure Copy) protocol?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!