• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

calling method from the same class

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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........

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
     
    Ranch Hand
    Posts: 33
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 2
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
    reply
      Bookmark Topic Watch Topic
    • New Topic