answersLogoWhite

0

Yes, if the variable is static. When a variable is static, is associated with the class itself and not any particular object (though it can be accessed through an object as well). An example is shown below:

class A

{

static int k = 5;

}

...

System.out.println(A.k);//5

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

Why use of external variables is discouraged?

External variables, or global variables, are generally frowned upon because any code with access to the variables can alter the variables in unexpected ways. Object oriented programming addresses this problem by allowing programmers to encapsulate those variables into an object (often a singleton object) which provides far greater control over how those variables may be altered.


What is basic unit of encapsulation?

A Class. It encapsulates its variables and methods into it.


Can a static method access instance variables?

Variables cannot access variables; only methods can access variables. Non-static methods (also known as instance methods) are local to an object of the class and therefore have access to a "this" reference (referring to the current instance of the class, the object upon which the method was invoked), but static variables are local to the class itself. These variables are shared by all objects of the class and are therefore accessible to non-static methods. Static variable are also accessible to static methods and are therefore accessible even when no objects of the class exist.


Effect of assigning one object reference variable to another object reference variable?

In that case, both variables will point to the same object. Changes done through one object reference will also be visible if you access the object through the other object reference.In that case, both variables will point to the same object. Changes done through one object reference will also be visible if you access the object through the other object reference.In that case, both variables will point to the same object. Changes done through one object reference will also be visible if you access the object through the other object reference.In that case, both variables will point to the same object. Changes done through one object reference will also be visible if you access the object through the other object reference.


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.

Related Questions

Which two variables show a INVERSE relationship?

For an object in motion without any acceleration, velocity and time.


Why you write a string with S capital?

A String in Java is an object, just like an Integer, which means creating them calls their class file, which has to be capitalized. Variables like int and float are primitive variables, meaning an object isn't created to hold them, so they aren't capitalized.


Why use of external variables is discouraged?

External variables, or global variables, are generally frowned upon because any code with access to the variables can alter the variables in unexpected ways. Object oriented programming addresses this problem by allowing programmers to encapsulate those variables into an object (often a singleton object) which provides far greater control over how those variables may be altered.


What is instance method?

An instance method is nothing but a normal java method. They can be invoked only by creating an object of the class that contains the method definition. Unlike static methods that can be invoked without creating an object of the class.


What creates static charge without contact?

Static charge can be created without contact through the process of induction. When a charged object is brought near a neutral object, the charges within the neutral object are rearranged, creating a separation of charges and resulting in a static charge on the object without direct contact.


What are the two variables that are important in momentum?

The two important variables in momentum are the mass of the object and its velocity. Momentum is calculated by multiplying an object's mass by its velocity.


Why use static?

Static is a keyword which is used to call the methods or variables without creation of that class object. It will directly calls the respective method and varialbles.


What are instance variables?

These are normal variables declared within a class that are attached to an object instance of a class.


What is need of static method?

If you need to access a method without creating an object of corresponding class, it need to be a static method.


What is basic unit of encapsulation?

A Class. It encapsulates its variables and methods into it.


Can a static method access instance variables?

Variables cannot access variables; only methods can access variables. Non-static methods (also known as instance methods) are local to an object of the class and therefore have access to a "this" reference (referring to the current instance of the class, the object upon which the method was invoked), but static variables are local to the class itself. These variables are shared by all objects of the class and are therefore accessible to non-static methods. Static variable are also accessible to static methods and are therefore accessible even when no objects of the class exist.


What variables can affect an object floating?

Air Resistance