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
Write an SQL statement to display for every restaurant the name of the restaurant (where the name of the restaurant consists of
Rainbow [258]

Using the knowledge in computational language in SQL it is possible to write the code that display for every restaurant the name of the restaurant  and for every category of menu item its description.

<h3>Writting the code:</h3>

<em>INSERT INTO Dish </em><em>Values</em><em>(13, 'Spring Rolls', 'ap');</em>

<em>INSERT INTO Dish Values(15, 'Pad Thai', 'en'); </em>

<em>INSERT INTO Dish Values(16, 'Pot Stickers', 'ap');    </em>

<em>INSERT INTO Dish Values(22, 'Masaman Curry', 'en');   </em>

<em>INSERT INTO Dish Values(10, 'Custard', 'ds');   </em>

<em>INSERT INTO Dish Values(12, 'Garlic Bread', 'ap');    </em>

<em>INSERT INTO Dish Values(44, 'Salad', 'ap');    </em>

<em>INSERT INTO Dish Values(07, 'Cheese Pizza', 'en');   </em>

<em>INSERT INTO Dish Values(19, 'Pepperoni Pizza', 'en');    </em>

<em>INSERT INTO Dish Values(77, 'Veggie Supreme Pizza', 'en');</em>

<em />

<em>INSERT </em><em>INTO MenuItem Values(0, 0, 13, 8.00);</em>

<em>INSERT INTO </em><em>MenuItem </em><em>Values(1, 0, 16, 9.00);</em>

<em>INSERT INTO MenuItem Values(2, 0, 44, 10.00);</em>

<em>INSERT INTO MenuItem Values(3, 0, 15, 19.00);</em>

<em>INSERT INTO MenuItem Values(4, 0, 22, 19.00);</em>

<em>INSERT INTO MenuItem Values(5, 3, 44, 6.25);</em>

<em>INSERT INTO MenuItem Values(6, 3, 12, 5.50);</em>

<em>INSERT INTO MenuItem Values(7, 3, 07, 12.50);</em>

<em>INSERT INTO MenuItem Values(8, 3, 19, 13.50);</em>

<em>INSERT INTO MenuItem Values(9, 5, 13, 6.00);</em>

<em>INSERT INTO MenuItem Values(10, 5, 15, 15.00);</em>

<em>INSERT INTO MenuItem Values(11, 5, 22, 14.00);</em>

See more about SQL atbrainly.com/question/13068613

#SPJ1

4 0
1 year ago
From which Menu option you can change page setup in MS Word​
marissa [1.9K]

page layout tab or the page setup dialog box

8 0
2 years ago
Windows, Apple’s Mac OS, and Unix/Linux are just some of the most common what?
34kurt
Most common PC operating systems
7 0
3 years ago
Read 2 more answers
What happens if i unplug my alarm system?
Dafna11 [192]
It loses power and most likely stops working
6 0
3 years ago
When Kristy recently started a photography business, she downloaded Photoshop to her computer to edit her photos. She notices he
Evgesh-ka [11]

Answer: A. System window and C. System Information window

Explanation:

Hi, RAM stands for Random Access Memory. RAM stores information about running programs in your computer, as long the computer is on.

To know how much RAM is installed on a system you can use the system window tool.

In windows 10 Right click on "Start Menu" and click on "System" in pop-up menu to open "System" window.

System window will show basic information of the computer, including the amount of RAM installed.

Also you can Type "System Information" in the search box, and select "System Information" from search results.

"System Information" window shows a more detailed system summary, of hardware resources and devices. Incluiding RAM.

Feel free to ask for more if needed or if you did not understand something.

7 0
3 years ago
Other questions:
  • If you specify a user without specifying a hostname, mysql will
    13·1 answer
  • A motherboard has four DIMM slots; three slots are gray and the fourth is black. What type of memory is this board designed to u
    6·1 answer
  • IDE devices require the use of a controller mounted on the motherboard. True False
    14·2 answers
  • An equation that performs a calculation is a formula. True or false quest
    9·1 answer
  • GAMER OYUNCU KOLTUĞU % YERLİ
    6·1 answer
  • Explain the impacts of computer in education
    6·2 answers
  • Any one know??please let me know
    15·2 answers
  • Match the parts of the website address with its correct explanation. http://www.usa.gov/Agencies/federal.shtm/​
    5·2 answers
  • In ip address 202.54.15.178, 15.178 is ______ address.
    8·1 answer
  • In the bremmer article, the author states that _________ translates into greater risks.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!