answersLogoWhite

0


Best Answer

No. Not directly, unless you pass a reference to that variable when you call a method.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can variables declared inside of methods be accessible to other methods in the same class?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

When variables are declared in the body of a method they are know as what?

Local Variables There are two types of variables based on the location of declaration 1. Instance Variables- Declared inside a class, but outside of any method's body. 2. Local Variables- Declared inside a method's body inside a class.


It is perfectly legal to any instance variable inside of a static method?

No. You will get compilation errors. The complier will complain that you are trying to access non static variables from inside a static method. A static method can access only static variables.


What is a structure member?

methods and variables inside the structure is callled structure member


whose variables are also known as global variables?

The variables which are declared outside the main() function is known as global variables and they can be used anywhere in the program. And, the variables which used declare inside the main() function is known as local variables and they can be used inside the main() function only. Example: #include<stdio.h> #include<conio.h> int x,y; // global variables void main() { int a,b; // Local variables ------------ ---------------------- --------------------- getch(); }


Why all variables are declared with in the function?

It is not necessary to to declare variables inside the function in C. If you declare a variable inside a function, the variable becomes local for the function and another variable of same name can be declared in any other function, but you can not use the variable declared in other function. When you declare any variable outside the function body then the variable becomes global and can be used in any function of the program. Note: errno is an example for a variable declared outside any function.

Related questions

Can variable declared in one scriplet access in another scriplet?

No. Variables declared inside a scriptlet are like method local variables which are not accessible outside the scriptlet/method.


When variables are declared in the body of a method they are know as what?

Local Variables There are two types of variables based on the location of declaration 1. Instance Variables- Declared inside a class, but outside of any method's body. 2. Local Variables- Declared inside a method's body inside a class.


It is perfectly legal to any instance variable inside of a static method?

No. You will get compilation errors. The complier will complain that you are trying to access non static variables from inside a static method. A static method can access only static variables.


What is a structure member?

methods and variables inside the structure is callled structure member


What is meant by a class in java programming?

Class - A class can be defined as a template/ blue print that describe the behaviors/states that object of its type support.Classes in Java:A class is a blue print from which individual objects are created.A sample of a class is given below: public class Dog{ String breed; int age; String color; void barking(){ } void hungry(){ } void sleeping(){ } }A class can contain any of the following variable types.Local variables . variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has completed.Instance variables . Instance variables are variables within a class but outside any method. These variables are instantiated when the class is loaded. Instance variables can be accessed from inside any method, constructor or blocks of that particular class.Class variables . Class variables are variables declared with in a class, outside any method, with the static keyword.A class can have any number of methods to access the value of various kind of methods. In the above example, barking(), hungry() and sleeping() are variables.


whose variables are also known as global variables?

The variables which are declared outside the main() function is known as global variables and they can be used anywhere in the program. And, the variables which used declare inside the main() function is known as local variables and they can be used inside the main() function only. Example: #include<stdio.h> #include<conio.h> int x,y; // global variables void main() { int a,b; // Local variables ------------ ---------------------- --------------------- getch(); }


Can Methods be declared in any order in a class.?

Yes. There is no specific order in which the compiler expects methods to be present. As long as the method is inside the class it is perfectly fine.


Why all variables are declared with in the function?

It is not necessary to to declare variables inside the function in C. If you declare a variable inside a function, the variable becomes local for the function and another variable of same name can be declared in any other function, but you can not use the variable declared in other function. When you declare any variable outside the function body then the variable becomes global and can be used in any function of the program. Note: errno is an example for a variable declared outside any function.


Why protected access specifier is not in interfaces?

Because an interface is like a contract/skeleton which decides what the implementing class has to do. So, if any entity in an interface is protected, they would not be available to the class that is implementing the interface. Hence, all the variables and methods declared inside an interface are public by default


What are Java enums?

An enum, short for enumerated type, is a variable type that can only take on the values that are declared inside the enum declaration. An enum is declared like a class, except the word "class" is replaced by the word "enum", and the class body is replaced by a list of values that a variable of that type can take on. You can also include methods, instance variables, and constructors in an enum.


What is the purpose of object oriented programming?

The answer lies in difference in Object oriented and variable based technology. Object oriented technology has a lot of benefits. One of which is that it eliminates declaration of variables for every time usage. It means that disk space is saved as variables are declared only once and only object is created further which gets an instance of these variables. It makes logic to easy implement and understand. Its systematic way of implementing a problem statement.


What is the scope of any variable?

The Scope of a variable defines the areas of a program where this variable would be visible and can be used. For ex: a. Method variables - are visible only inside the method where they are declared and hence their scope is only the method b. Class variables - are visible inside the class and can be used by any method inside the class and hence their scope is the whole class.