This week's book giveaway is in the Go forum.
We're giving away four copies of Head First Go and have Jay McGavren on-line!
See this thread for details.
Win a copy of Head First Go this week in the Go 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:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

OCA related question regarding interfaces  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all!

I am currently preparing for the OCA exam. When doing the training test that was included in the McGrawHill OCA preparation book, I stumbled upon a strange question, that I could not answer correctly. I think there might be an error in one of the answers:



Why is answer G incorrect?
How can i call .super on an interface? What am I missing?

If someone can help, thank you in advance!
 
Michael Lich
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will quote the excellent answer I got in another forum:



In this case, the explicit interface .super call is necessary!




so, the answer in the exam software is correct after all, although the behavior is somehow hidden.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line B will not compile because we are trying to decrease the visibility of the interface method while overriding the method. All the methods in an interface are by default 'public'. While overriding the method has to have the same visibility has to be either same or more. As public access specifier has the highest visibility, the overridden methods can be only public.

Line D is correct. In case of default methods in interfaces, one definition of method is already there. We can override the method in the implemented class as is done in the question. To call the method definition available in the interface, we need an instance of the interface which we can get with the help of InterfaceName.super keyword. We cannot say Hero.m1() as it is not a static method.


 
Marshal
Posts: 63485
207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch both of you.

Is that the book by Sierra and Bates? I wasn't familiar with InterfaceName.super.... before
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!