This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin Cookbook and have Ken Kousen on-line!
See this thread for details.
Win a copy of Kotlin Cookbook this week in the Kotlin forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

super keyword and Super Classes.

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Question about Super class and super keyword.


My Question is Why line 1 and line 2 are illegal to call.

 
Marshal
Posts: 67036
255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please always tell us where such code comes from. Is it from a book, website or did you write it yourself?

Plain simple super means the direct superclass (Flash) and Flash doesn't have an assemble() method. So you can't call that. It does however have a power() method which prints “Hello Bunny ”. You have some strange names for your methods
Batman.super.assemble() is indistinguishable from super.assemble() so that line has exactly the same problem.
Team.super obviously means that part of the object which is inherited from Team. That does have an assemble() method.
 
Ng Sharma
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please always tell us where such code comes from. Is it from a book, website or did you write it yourself?

Plain simple super means the direct superclass (Flash) and Flash doesn't have an assemble() method. So you can't call that. It does however have a power() method which prints “Hello Bunny ”. You have some strange names for your methods
Batman.super.assemble() is indistinguishable from super.assemble() so that line has exactly the same problem.
Team.super obviously means that part of the object which is inherited from Team. That does have an assemble() method.



This code write my self. please explain more clearly.
 
Campbell Ritchie
Marshal
Posts: 67036
255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ng Sharma wrote:. . . This code write my self . . .

Thank you.

Line 12 calls the power() method, which was inherited from the Flash class. Because you didn't override power(), that method is the same as in its superclass.

FlashObject.power()
          ↑
          ↑
→→BatmanObject.power() // method called

Line 13 calls the power() method as it is in the Flash class.

FlashObject.power() // method called
      ↑
      ↑
BatmanObject.power()

Line 14 appears to do exactly the same as inexa0;13.
Watch this space. More to come.
 
Campbell Ritchie
Marshal
Posts: 67036
255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 16 calls the assemble() method, which is inherited from Team.

Team.assemble()
         ↑
         ↑
→→BatmanObject.assemble() // method called

Again, you didn't override the method, so it is exactly the same as in the Team interface. But if you try to use plain simple super, you are trying to do this:-

FlashObject.assemble() // no such method
    ↗   ↑
↗       ↑
BatmanObject.assemble()

Flash hasn't got an assemble() method, so that won't compile
If however you add Team., you would appear to be getting the part of the object inherited from Team.

Team.assemble()  FlashObject.assemble() // no such method
                                   ↑
                                  ↑
BatmanObject.assemble()

 
Water proof donuts! Eat them while reading this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!