• 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

Abstract class

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have a doubt regarding the excersise 1.1 page 18-K&B book(with my scenario)
If i create the abstract class Fruit, say the class contains
abstract method x() and non-abstract methods y() and z(), and if i
make Apple class(abstract) extending the Fruit class.
Then there is no way i can access the non-abstract methods of class
Fruit from Apple though it is extending it(bcoz i cant create objects
for Apple class as its abstract).
I would like to know if there is any way i can access the non-abstract
methods of Fruit class from Apple class bcoz Apple extends Fruit?


Thanks in advance
Asha
 
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As long as those methods in fruit are not private you should be able to call them from Apple.
 
asha ganapathy
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The non-abstract methods in the Fruit class are not private, then how do i call them from Apple which is an abstract class?
 
asha ganapathy
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a different Scenario.. :roll:
I found that an Abstract class can extend Non-Abstract class.i would like to know where kind of inheritance is used?
 
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey asha as you have mentioned that both Fruit and Apple are abstrat classes
and you want to inherit the nonabstarct methods of super class Fruit in apple

You must be knowing that abstract classes do not consist of implementation of methods just methods are declared,and still you want to get the non abstract methods in the abstract class apple you just override those methods as shown in below code..........




i hope it helps you.......
 
reply
    Bookmark Topic Watch Topic
  • New Topic