q-7 )is it possible to maintain local variable and static variable with same name?
ans:yes it is possible to maintain local and static variable with same name.
to access static variable we can use class name.
q-8)is it possible to maintain local variable and non static variable with same name?
yes,it is possible to maintain local variable and non static variable with same name.
to access the non static variable we cvan use object references.
for ex:-
class test
{
static int a=10;
public static void main(String[] args)
{
System.out.println(a);//10
int a=50;
System.out.println(a);//50
System.out.println(test.a);//10
}
}
No comments:
Post a Comment