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

16y ago

What else can I help you with?

Continue Learning about Engineering

What is the top level object in javascript?

In JavaScript, the top-level object is the global object, which is window in browsers and global in Node.js. This object serves as the default context for all variables and functions defined in the global scope. It allows for the storage and access of global variables and functions, making them accessible throughout the code. In strict mode, however, the global context behaves slightly differently, and variables defined without var, let, or const do not become properties of the global object.


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.


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 basic unit of encapsulation?

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

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.


What is the top level object in javascript?

In JavaScript, the top-level object is the global object, which is window in browsers and global in Node.js. This object serves as the default context for all variables and functions defined in the global scope. It allows for the storage and access of global variables and functions, making them accessible throughout the code. In strict mode, however, the global context behaves slightly differently, and variables defined without var, let, or const do not become properties of the global object.


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 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 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 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.


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 basic unit of encapsulation?

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