File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes A question about Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A question about "interface"" Watch "A question about "interface"" New topic
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: 24166
    
  30

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A question about "interface"
 
Similar Threads
Instance of Operator
When did the Stateful Sessionbean created?
Client programming and class author discrepincies
casting
variables in inteface