Saturday, 31 August 2013

Compiler Error while Overloading - Java

Compiler Error while Overloading - Java

class parent
{
public void disp(int i) {System.out.println("int");}
}
class child extends parent
{
private void disp(long l){System.out.println("long");}
}
class impl
{
public static void main(String...args)
{
child c = new child();
c.disp(0l); //Line 1
}
}
Compiler complains as below
inh6.java:27: error: disp(long) has private access in child
c.disp(0l);
The input given is 0L and I am trying to overload the disp() method in
child class.

No comments:

Post a Comment