• 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

Overriding

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class ClassA {
private void doIt() {
System.out.println("Base class: doIt()");
}
}

class ClassB extends ClassA {
private void doIt() {
System.out.println("Subclass: doIt()");
}
}

Is it an example of
A) Overloading
B) overriding
c) None of the above


My answer is b.. But the answer given C..

Can somebody explain??
 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer C is correct.

1. You can not override a method that you can't inherit. In this scenario, though it looks like override, the matter of fact is, method in the parent class is not accessible in child clas because, that metho is a private method and a private method is not visible outside the class. So when child class inherits the parent class, it doesn't see that method. So obviously it's neither overiding nor overloading.
 
Abi Raj
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Sekar.. I was so tired.. I didnt realize it is a private method.
 
reply
    Bookmark Topic Watch Topic
  • New Topic