• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do you call an overridden method  RSS feed

 
sandy chauhan
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public abstract class Fi_nal1 {

public abstract void sub();
public abstract void main1();
public void simple()
{
System.out.println("Hiiiii");
}

}







class Fi_nal extends Fi_nal1 implements Filla1{


public void sub()
{
System.out.println("I M in Sub");

}
public void main1()
{
System.out.println("I M in Main");
}

public void simple()
{
System.out.println("Hii I am in Fi_nal");
}
public void fill1()
{
System.out.println("Hii I am in Fill1");

}
public void fill2()
{
System.out.println("Hii I am in Fill2");
}
public void fill3()
{
System.out.println("Hii I am in Fill3");
System.out.println(a);
}

}





public class F1 {
public static void main(String args[])
{
Fi_nal f=new Fi_nal();
f.main1();
f.sub();
f.simple(); // how can I call the method simple from the Abstract class(Fi_nal1) which is a super class for Fi_nal and Fi_nal also have the same method simple)
}
}




Please reply

In class F1 if I call f.simple() method it calls the method from class Fi_nal so how can I call method sinple() from the abstract class Fi_nal1 ?
 
Saif Asif
Ranch Hand
Posts: 440
Eclipse IDE Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sandy,
To call in a super class method you just use the keyword super. Like e.g if the name of the method is "someRandomMethood()" , then you can invoke it with
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Welcome to the Ranch.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember you can only use the keyword super in a non‑static context in the direct subclass.
 
sandy chauhan
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Added code tags - see UseCodeTags for details]




Please reply

In class F1 if I call f.simple() method it calls the method from class Fi_nal so how can I call method sinple() from the abstract class Fi_nal1 ?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't. That's not how object-oriented languages generally work.

The good news is that you should never have to. If you've got a real situation where you think you need to be able to do this, maybe we can help you improve the design so that you don't.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!