wood burning stoves 2.0*
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
Author

calling method from the same class

Shivaja Karthik
Greenhorn

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
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

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] [Bear's FrontMan] [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
    Greenhorn

    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: http://aspose.com/file-tools
     
    subject: calling method from the same class
     
    Similar Threads
    notify() problem in Thread
    cannot resolve symbol
    Could not find or load main class StDemo
    Getting two java code blocks to work together
    Have problem in stack ! not able to get the output