Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Legal Method Declarations II

 
Dan Mortimer
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Richard!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic