+ 1
Printing variable of class level if local and class level is having same name.
What if there are two variable with the same name one is local and other is at class level. If I want to print class level variable then how can i ?
2 Answers
+ 2
Assuming youâre talking about java, the âthisâ keyword will allow you to reference a current class variable. https://www.javatpoint.com/this-keyword
public class Program
{
String s = "This is an instance variable";
void myMethod() {
String s = "this is a local variable";
System.out.println(this.s);
System.out.println(s);
}
public static void main(String[] args) {
new Program().myMethod();
}
}
0
Do you have any code example?