Two Laptop Bag
The moose likes Beginning Java and the fly likes Abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstract class" Watch "Abstract class" New topic

Abstract class

asha ganapathy
Ranch Hand

Joined: Nov 03, 2006
Posts: 54
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
David McCombs
Ranch Hand

Joined: Oct 17, 2006
Posts: 212
As long as those methods in fruit are not private you should be able to call them from Apple.

"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."- Stan Kelly-Bootle
asha ganapathy
Ranch Hand

Joined: Nov 03, 2006
Posts: 54
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

Joined: Nov 03, 2006
Posts: 54
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?
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
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.......
I agree. Here's the link:
subject: Abstract class
It's not a secret anymore!