• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Legal Method Declarations II

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Richard!
reply
    Bookmark Topic Watch Topic
  • New Topic