Question

In: Computer Science

In java, what does it mean when a variable "exists" from its declaration to }?

In java, what does it mean when a variable "exists" from its declaration to }?

Solutions

Expert Solution

It means that you can use that variable in that block only.. You can not use that variable outside that block

Please find the below example

class Test{
        public void fun(){
                int x=10;
                // you can use x from here to 
                System.out.prinln();
                System.out.prinln();
                System.out.prinln();
                System.out.prinln();
                System.out.prinln();
                System.out.prinln();
                // here only
        }
        public void sun(){
                // you can't use the x here 
        }
}

Related Solutions

what does it mean when an independent variable is significant? in Stats
what does it mean when an independent variable is significant? in Stats
When a variable is noted to be immutable, what does this mean? What is the advantage/...
When a variable is noted to be immutable, what does this mean? What is the advantage/ disadvantage of immutable variables?
How do we know when social or political inequality exists? What does it mean to be...
How do we know when social or political inequality exists? What does it mean to be “equal”? Are equity and equality the same thing? Should our constitution merely provide the potential for equality to exist? Or should it guarantee an equal outcome?
1. In Java, what does the last line mean? What does scan.nextLine(); mean?
1. In Java, what does the last line mean? What does scan.nextLine(); mean?import java.util.Scanner;Scanner scan = new Scanner (System.in);message = scan.nextLine();2. Assuming that a Random object has been created called generator, what is the range of the result of each of the following expressions? Also, do each example using nextFloat()•generator.nextInt(20)•generator.nextInt(8) + 1•generator.nextInt(100) – 50
What does it mean when Java short-circuits a logical and/or? Why might you not want to...
What does it mean when Java short-circuits a logical and/or? Why might you not want to short-circuit a logical operation?
Question 1: When using a multimeter, what does it mean when the meter is on its...
Question 1: When using a multimeter, what does it mean when the meter is on its “best setting”? Question 2: When using a multimeter, why is it important to always check the meter to make sure that you are making a measurement on its best setting? Does this procedure of a “Best Setting” also apply to measurements of voltage and current? Question 3: When using a multimeter, which settings are the best for each resistor? How many digits are displayed...
What does it mean to standardize random variable ?
What does it mean to standardize random variable ?
What does it mean for its shareholders when a company is applying most of its revenue...
What does it mean for its shareholders when a company is applying most of its revenue to the repayment of loans?
in java my code double price[] = {26.99, 22.99, 13.99, 56.99, 38.99}; // Variable Declaration Scanner...
in java my code double price[] = {26.99, 22.99, 13.99, 56.99, 38.99}; // Variable Declaration Scanner keyIn = new Scanner(System.in); //Header System.out.println( "----------------------------------------\n" + " Grocery Shop Price Calculator \n" + "----------------------------------------\n") ; System.out.print ("Please enter the quantities for each item in the list? "); double totalCost = 0; double fishAmount = 0; for(int i=0; i<price.length; i++) { int items = Integer.parseInt(keyIn.nextLine()); if(i==4) fishAmount = price[i]*items; else totalCost = totalCost + price [i]*items; } System.out.print("Do you have the membership(Y/N) ");...
What does it mean for a compound to become its "stable form" when it transitions? Is...
What does it mean for a compound to become its "stable form" when it transitions? Is this related to equilibrium?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT