jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Legal Method Declarations II Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Legal Method Declarations II" Watch "Legal Method Declarations II" New topic
Author

Legal Method Declarations II

Dan Mortimer
Greenhorn

Joined: Jun 01, 2004
Posts: 18
I have the following code:

public abstract class TestAbstract {
abstract String specialMethod();

private native void abstractMethod();

void sayHello() {
System.out.println("Hello");
}
}

It compiles fine, but I am a bit confused because I have an abstract method declaration which does not use the keyword abstract:

private native void abstractMethod();

The compiler is fine with the above decalration, but it doesnt't like the following:

String abstractMethod();

...so, why can I get away without using the abstract keyword in the first method declaration and not the second...?

Thanks!
Richard Bradford
Ranch Hand

Joined: Apr 20, 2004
Posts: 48
The first method is legal because you have used the native keyword.
Methods that are declared as native do not contain a method body as they implemented elsewhere in a seperate language source file such as a c++ class file.
Dan Mortimer
Greenhorn

Joined: Jun 01, 2004
Posts: 18
Thanks Richard!
 
 
subject: Legal Method Declarations II
 
Similar Threads
native abstract method
Can an interface be private or protected.?
it should be more ambiguous then previous version.
Sierra and Bates - Self Test Chapter 2 Question 5
Class definition