[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

Same name of variable

Can a class variable can have same name as an auto variable?
0
sanjeev77
Asked:
sanjeev77
1 Solution
 
g_senthilkumarCommented:
Hi,
  You mean auto variable means local variable which is declared inside a method or block.You can have class variable and autovariable with the same name.
   ex)
    public void display()
    {
      int no;
      this.no=no*10;
    }
    So whenever you are referring the instance variable you can refer with "this" object.If the variable is class variable or static variable,then it can be accessed only inside the static method.
   That time you can do like this,
   Sample.no=no*10;
   Assume that Sample is a class name.

   
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now