File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes calling method from the same class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "calling method from the same class" Watch "calling method from the same class" New topic

calling method from the same class

Shivaja Karthik

Joined: May 30, 2013
Posts: 2
Hi All.....i'm a novice in java....just started learning...hope this forum helps me to gain more knowledge in java.....My question is how do we call a method from the same class.....

here is my code: i'm trying to implement interface, inheritance, method over riding, anonymous class and interface reference all in this program.....the code worked fine without method overriding and anonymous class....have highlighted the error statement in red.....can someone please say where i have gone wrong........

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

Here are a few helpful hints to help you get the help you need:
  • Sentences end with a single period character followed by a space character. Not multiple period characters. Making your post harder to read is not a great way to try and get help.
  • Properly indent youyr code. Unindented code is hard to inspect and, again, making your post harder to read than it needs to be is not the best way to get help.
  • Don't try to put color directives in your code. As you can see, they do not work.

  • Welcome to the Ranch, and I hope these tips help.

    [Asking smart questions] [About Bear] [Books by Bear]
    Shashank Gollapudi
    Ranch Hand

    Joined: Jan 19, 2012
    Posts: 33
    HI Shivaja,

    The error on the line 45 from your code is you are instantiating a subclass for an abstract class which is not completely defined. Use the following way instead

    Secondly the error on line 54 is you are trying to restrict the access modifier, as the methods in an interface are always public , where as you are changing it to default access.

    Please let me know if something is unclear
    Shivaja Karthik

    Joined: May 30, 2013
    Posts: 2
    Hi Shashank Gollapudi

    Thanks for your quick response. your comments helped. the code is working fine now :-)

    Please clarify the following too:

    Does this mean we are creating an instance for an "Abstract" anonymous class. why i am mentioning abstract is it includes just 1method of the interface. is my understanding right?

    Also how can i have interface reference for an abstract class without including pop(int) in the example given. i tried as follows

    It gave me a compiler error stating anonymous class is not abstract and doesnt override method pop(int). while creating a reference variable for an abstract class should the anonymous class definitely invoke the method in the interface that is left out in the abstract class?. then wats the point in creating an abstract class?...quiet confusing.
    I agree. Here's the link:
    subject: calling method from the same class
    It's not a secret anymore!