answersLogoWhite

0

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.

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

How nesting of methods is done in java?

No, Java only allows a method to be defined within a class, not within another method.


What is the relationship between inheritance methods and the keyword final?

They are inversely related. That is: If you declare a method as final you cannot overridden in the child class If you declare a class as final you cannot inherit it in any other class.


What allows a new class to automatically pick up all the data and methods of an existing class?

Inheritance allows a new class to automatically pick up all the protected and public data and methods of an existing class. To do so, the new class must be derived from the existing class. Private data and methods remain private to the existing class, the base class.


What do you mean by classes within the classes?

You can declare and implement a class within a class...class abc {...class def {...}}The class def is scoped and known only within the context of abc. It is possible to declare instances of def as member variables of abc, however, for this to work correctly, they should be private, because methods of def, not even public methods, do not exist outside of the scope of abc.


The actions in a java class are called?

The actions in a java class are called methods.


Can additional methods of base class be hidden from the derived class in object oriented software?

Yes. During inheritance only the public members of the parent class are visible to the child class. If you declare a method or a variable as private, the child class cannot access it. In other words, the methods and variables are hidden from the derived class.


How can you create a class which cannot be inheritable?

Declare it final.


What is it called when you watch a class?

When you watch a class, it is often referred to as "class observation." This practice allows educators to gain insights into teaching methods, student engagement, and classroom dynamics. Class observations can be used for professional development, peer feedback, or as part of teacher evaluations.


What is the difference between a class method and an instance method?

Instance methods can be called by the object of a Class whereas static method are called by the Class. When objects of a Class are created, they have their own copy of instance methods and variables, stored in different memory locations. Static Methods and variables are shared among all the objects of the Class, stored in one fixed location in memory.Static methods cannotaccess instance variables or instance methods directly-they must use an object reference. Also, class methods cannot use the this keyword as there is no instance for this to refer to.


It allows the creation of a new class from a base class?

It is called Inheritance


When do you declare a member as static in java?

You declare a member static whenever the member should be regarded as being local to the class rather than being local to objects of the class. Static members are shared by all instances of the class. Static methods of a class differ from ordinary members in that they do not have an implicit "this" reference, which means they can be invoked even when no instances of the class exist.


Is it possible to call static methods with out creating object?

Yes, we can access all methods which declare with static means then we can access.. ex: class s{ static method() { System.out.println("Welcome"); } } class fun{ public static void main(String args[]) { method(); } }