September 1, 2009 at 6:27 PM
How do you access non static method of a class ?
i.e. obj.method() right !
So, if u have a class which is not having the given method how will u access it ?
Just study the following code carefully
System.out.print("a is "+a);
public static void main(String args)
B bobj=new B();
Lets forget about class A for timbing.
Look at class B...............
It does not have a member so called 'a' and not even show().
Hence compiler will definately give an error.
above prg compiles if We write class B as
class B extends A
Coming to ur prg.
The error is you can access Public_Demo1 member method only if have instantiated (created an object) of it in Public_Demo2.
So, try it out, as
public static void main(String ar)
Public_Demo1 pd=new Public_Demo1();
your prg will compile. you must be wondering why eg with no package statement is being provided to u. Its because classes/interfaces with no package statement is put into a default package thats without a name.
so eg provided will work similarly to which u have tried. if u still wish to add a package statement u can go ahead. Happy programming..............