| Author |
abstract class / method
|
janne kallio
Greenhorn
Joined: Oct 13, 2003
Posts: 16
|
|
Wondering about the following code: In one file I have got the code: package food; public abstract class Fruit { abstract void setColor(); abstract void setWeigh(); } and in JC26112003_6.java file I have the code as follows; import food.Fruit; class Apple extends Fruit { void setColor(){} void setWeigh(){} } public class JC26112003_6 { } Why am I getting compiler error out of this? Apple should be declared abstract Grateful to your explanation! janne
|
 |
Cathy Song
Ranch Hand
Joined: Aug 24, 2003
Posts: 270
|
|
Originally posted by janne kallio: Wondering about the following code: In one file I have got the code: package food; public abstract class Fruit { abstract void setColor(); //default modifier abstract void setWeigh(); //default modifier } and in JC26112003_6.java file I have the code as follows; import food.Fruit; class Apple extends Fruit { void setColor(){} void setWeigh(){} } public class JC26112003_6 { } Why am I getting compiler error out of this? Apple should be declared abstract Grateful to your explanation! janne
The access modifier of the abstract methods of class Fruit is default. This means that classes and subclasses of Fruit outside package food cant access the methods.
|
 |
janne kallio
Greenhorn
Joined: Oct 13, 2003
Posts: 16
|
|
package food; public abstract class Fruit { abstract void setColor(); //default modifier abstract void setWeigh(); //default modifier } The access modifier of the abstract methods of class Fruit is default. This means that classes and subclasses of Fruit outside package food cant access the methods. Cathy, are you saying that though I declared my Fruit class as public, it is considered as default access modifier, not as public modifier. janne
|
 |
dennis zined
Ranch Hand
Joined: Mar 07, 2003
Posts: 330
|
|
Hi Cathy, I saw your post at the Certification result forum and would like to congratulate you. Awesome score! Jane, if i may,...member accessibility is governed separately from class accessibility.
|
SCJP 1.4<br />SCWCD 1.4
|
 |
janne kallio
Greenhorn
Joined: Oct 13, 2003
Posts: 16
|
|
Ok, I got it. Thanks! I haven't yet reached that part in the S&B book. That's why the confusion. Congratulations, Cathy, for your excellent score! janne
|
 |
 |
|
|
subject: abstract class / method
|
|
|