| Author |
A question about "interface"
|
jeff yashero
Greenhorn
Joined: Sep 24, 2003
Posts: 5
|
|
/***************************/ abstract interface Car { public void Wheel(); ^^^^^^ } class BigCar implements Car { public void Wheel() { ^^^^^^ System.out.println("The bigcar have 4 wheels"); } } public class Test { public static void main(String[] args) { BigCar bc=new BigCar(); bc.Wheel(); } } /***************************/ I delete the keyword "public"(class BigCar & interface Car)... then compile it but...it compile error why??
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
All interfaces are abstract and all interface methods are public. Java lets you include these keywords in the interface definition, but they're redundant. The following is identical to yours in every respect: Now, when you implement an interface, since the interface methods are public, your implementations must be, too. When you change BigCar's Wheel() method to be non-public, you break that rule, so you get an error.
|
[Jess in Action][AskingGoodQuestions]
|
 |
nandu pc
Greenhorn
Joined: Oct 30, 2003
Posts: 2
|
|
Originally posted by jeff yashero: I delete the keyword "public"(class BigCar & interface Car)... then compile it but...it compile error why??
Moreover, you cannot access non-public members of a class from another class. so you shud get a comiple error at bc.Wheel() too. NaNdU
|
 |
jeff yashero
Greenhorn
Joined: Sep 24, 2003
Posts: 5
|
|
Thank you
|
 |
 |
|
|
subject: A question about "interface"
|
|
|