• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple Query related with Inheritance  RSS feed

 
Vaibhav Manwatkar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone , following is my programme... JavaDemo.java

class A
{
void fun1()
{
System.out.println("from A:fun1()");
}
void fun2()
{
fun1()
}
}

class B extends A
{
void fun1()
{
System.out.println("from B:fun1()");
}
}

class JavaDemo
{
public static void main(String arg[])
{
B bobj = new B();
b.fun2();
}
}

the call b.fun2() calls the fun1() of the B Class.... HOW to call fun1() of Class A...
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You really can't. When you designed B and overrode fun1() you specified you wanted to use B's fun1() instead of A's fun1(). B's fun1() can call super.fun1() but I think that's not quite what you wanted.

If you wrote A and I wrote B you might be upset that I overrode your method so I don't execute your code. Maybe you had critical security checks in there or something. See what the compiler says if you change A's fun1() to be "final".
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!