answersLogoWhite

0

It is, provided that the variable is also static or you're referencing the variable through an instance of you class.

class MyClass {

static int staticVariable;

int memberVariable;

public static void main(String[] args) {

// This is legal.

staticVariable = 10;

// This is not legal.

memberVariable = 10;

// This is legal.

MyClass mc = new MyClass();

mc.memberVariable = 10;

}

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

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 it called when java allows you to declare methods with the same name in a class?

Yes perfectly Legal Reason: The scope of a variable declared inside a method is only till the method's end. So by defining another variable of the same name inside a different method does not create any issues.


What is finalize method in java?

Finalize method is used when a variable becomes unreachable or of no use. it is finalize and garbage collection will free the memory used by it, which can be then reclaimed for some other variable


What are the rules on how to construct java constructor?

1. The constructor has to have the same name as the classthat it is in.2. It does not have a return type. If it has a return type, then it is a method (even though it is legal, it's not ideal to have name a method the same name as the class).3. It can use any access modifier (this includes private).4. The default constructor does not take arguments.5. The first statement in a constructor has to have a super() type or this() type. If this is not written, by default, it's super(). It's illegal to have it in any other line other than the first line.6. Constructors can only access static variables.7. Only constructors have access to another constructor.Remember that interfaces do not have a constructor.


What is method overriding in java?

Method overriding is when a child class redefines the same method as a parent class, with the same parameters. For example, the standard Java class java.util.LinkedHashSet extends java.util.HashSet. The method add() is overridden in LinkedHashSet. If you have a variable that is of type HashSet, and you call its add() method, it will call the appropriate implementation of add(), based on whether it is a HashSet or a LinkedHashSet. This is called polymorphism. Method overloading is defining several methods in the same class, that accept different numbers and types of parameters. In this case, the actual method called is decided at compile-time, based on the number and types of arguments. For instance, the method System.out.println() is overloaded, so that you can pass ints as well as Strings, and it will call a different version of the method. Overriding is an example of run time polymorphism. The JVM does not know which version of method would be called until the type of reference will be passed to the reference variable. It is also called Dynamic Method Dispatch. Overloading is an example of compile time polymorphism.

Related Questions

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 it called when java allows you to declare methods with the same name in a class?

Yes perfectly Legal Reason: The scope of a variable declared inside a method is only till the method's end. So by defining another variable of the same name inside a different method does not create any issues.


Is legal fee a fix cost or variable cost?

variable cost


Is it legal to transfer or modify the serial number on an electronic device?

No. It's fraud.


Is it legal to modify an air rifle by yourself?

It all depends on the country where you live


Is it legal to modify and then sell an existing product?

If the developer whom you bought the product allows you to modify the product and then resell it, then it's legal.On the other hand if the product you bought says that you cannot modify, re-produce or resell, then it's illegal.


What is legal method?

legal method is what steps a lawyer or someone involved in scandal to find the truth about what happened without doing something illegal themselves


Is it legal to remove a catalytic converter on your own car in Michigan?

It is not legal to modify the emissions sytem in any state. Doing so is a violation of Federal Law.


Is it possible to modify a prenuptial agreement after getting married?

Yes, it is possible to modify a prenuptial agreement after getting married through a postnuptial agreement, which is a legal document that outlines any changes to the original agreement.


Where can you find pivot T.V. static?

You can search it up on google. Then Mirror the video just for legal issues.


What is an equation that is true for every value of the variable?

legal equation * * * * * In mathematics, it is called an identity.


Can you modify football cleats to make them legal for soccer games?

yes u have to jump around util they break off