7) Will this code compile? // need clarification
[code:1emchxf8]
class Demo // Sub Class
{
static int var=9;
public static void func()
{
System.out.println("learning static keyword");
}
}
public class Main // Main class
{
public static void main(String s[])
{
Demo ob = new Demo();
ob.var=9;
ob.func();
}
}[/code:1emchxf8]
//Ans: ob.var=9; it can work but its not recommended.
you can access static method with object but its not recommended.