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
Eric is working on a computer that has a device driver error. Eric can find the name of the device driver however the actual dev
creativ13 [48]

Answer:

Windows\System32\drivers folder

Explanation:

8 0
3 years ago
Read 2 more answers
Is it safe for me to use normal glue to stick things on my laptop like stickers or pics?
vaieri [72.5K]

Answer:

I think you should be fine, as long as you're just sticking it to the backside of your laptop. (For MacBooks, this is the part of the laptop with the apple symbol.) You can easily wash glue off with a cleaner such as Goo Gone or Pledge. There's better solutions, like ordering a case for your computer and putting the stickers on there, but I guess it's fine to stick them onto your computer. I'll attach a photo of an example of case with stickers.

<em>Hope this helps! Feel free to give me Brainliest if you feel this helped. Have a good day, and feel free to comment any questions below you may have. :)</em>

5 0
3 years ago
Read 2 more answers
Write a program which will use a template version of search function(4 points): Randomly generate a list of 100 integers(1 point
Over [174]

Answer:

aye youngboyyyyy

Explanation:

3 0
3 years ago
Preventive Maintenance will will reduce potential hardware and Software Problems. Select two factors based on which Preventive m
zimovet [89]

Answer:

Computer location or environment

Computer Use

Explanation:

Preventive maintenance are maintenance done, on a routine or regular basis, to prevent the occurrence of downtime which are not planned due to the failure of equipment in the system, and to ensure continual functionality of the system

In a computer system, therefore, preventive maintenance should focus on conditions that are on the maximum limits of the specification of the system

Therefore, the preventive maintenance of the system of the computer system is based on;

1) The computer location, such as the presence of dust in the environment, that can clog the circuit board of the system, or exposure to liquid that require ensuring protective covering of parts, or the high temperatures, that may require extra cooling through the use of fans

2) The computer usage; Including how the computer is used, either continuously, or once in a while, the traffic the computer is experiencing, the presence of temporary files, and malicious programs, that require removal.

5 0
3 years ago
Develop a program working as a soda vending machine. The program should show the product menu with price and take user input for
Kipish [7]

Answer:

Explanation:

The following vending machine program is written in Python. It creates various functions to checkItems, check cash, check stock, calculate refund etc. It calls all the necessary functions inside the main() function. The output can be seen in the attached picture below.

class Item:

   def __init__(self, name, price, stock):

       self.name = name

       self.price = price

       self.stock = stock

   def updateStock(self, stock):

       self.stock = stock

   def buyFromStock(self):

       if self.stock == 0:

           # raise not item exception

           pass

       self.stock -= 1

class VendingMachine:

   def __init__(self):

       self.amount = 0

       self.items = []

   def addItem(self, item):

       self.items.append(item)

   def showItems(self):

       print('Items in Vending Machine \n----------------')

       for item in self.items:

           if item.stock == 0:

               self.items.remove(item)

       for item in self.items:

           print(item.name, item.price)

       print('----------------\n')

   def addCash(self, money):

       self.amount = self.amount + money

   def buyItem(self, item):

       if self.amount < item.price:

           print('You can\'t but this item. Insert more coins.')

       else:

           self.amount -= item.price

           item.buyFromStock()

           print('You chose ' +item.name)

           print('Cash remaining: ' + str(self.amount))

   def containsItem(self, wanted):

       ret = False

       for item in self.items:

           if item.name == wanted:

               ret = True

               break

       return ret

   def getItem(self, wanted):

       ret = None

       for item in self.items:

           if item.name == wanted:

               ret = item

               break

       return ret

   def insertAmountForItem(self, item):

       price = item.price

       while self.amount < price:

               self.amount = self.amount + float(input('insert ' + str(price - self.amount) + ': '))

   def calcRefund(self):

       if self.amount > 0:

           print(self.amount + " refunded.")

           self.amount = 0

       print('Thank you!\n')

def main():

   machine = VendingMachine()

   item1 = Item('Kit Kat',  1.5,  2)

   item2 = Item('Potato Chips', 1.75,  1)

   item3 = Item('Snickers',  2.0,  3)

   item4 = Item('Gum',  0.50, 1)

   item5 = Item('Doritos',0.75,  3)

   machine.addItem(item1)

   machine.addItem(item2)

   machine.addItem(item3)

   machine.addItem(item4)

   machine.addItem(item5)

   print('Welcome!\n----------------')

   continueBuying = True

   while continueBuying == True:

       machine.showItems()

       selected = input('select item: ')

       if machine.containsItem(selected):

           item = machine.getItem(selected)

           machine.insertAmountForItem(item)

           machine.buyItem(item)

           a = input('buy something else? (y/n): ')

           if a == 'n':

               continueBuying = False

               machine.calcRefund()

           else:

               continue

       else:

           print('Item not available. Select another item.')

           continue

if __name__ == "__main__":

   main()

8 0
3 years ago
Other questions:
  • What does microsoft recommend for large organizations requiring desktop virtualization for many clients? quizlewt?
    10·1 answer
  • Which is a benefit of peer-to-peer networking?
    10·1 answer
  • What are the principal cybersecurity threats, both internal and external, and the principal safeguards that have been developed
    13·1 answer
  • Write a sequence of statements that finds the first comma in the string line, and assigns to the variable clause the portion of
    13·1 answer
  • Which type of development metrics does Instagram most improve when it releases an update in the App Store to fix errors its cust
    15·1 answer
  • 1. Why is it important for IT technicians to keep documentation on computers for which they are
    13·1 answer
  • Match each method of communication with its intended purpose.
    14·1 answer
  • Name the factors which of the following resources relate to :
    7·1 answer
  • Select the correct answer.
    14·1 answer
  • How do I find unwanted programs on my computer?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!