• 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

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Guru's

The following questions from Kathy.

I won�t agree with the answer 5 (5 � private native void m1 () .
Because this method is ending with semicolon instead of curly brace.
Pls let me know am i wrong.

Question :-

5. How many of the following are legal method declarations?
1 � protected abstract void m1();
2 � static final void m1(){}
3 � transient private native void m1() {}
4 � synchronized public final void m1() {}
5 � private native void m1();
6 � static final synchronized protected void m1() {}

A. 1
B. 2
C. 3
D. 4
E. 5
F. All of them

Answer:-

5. E. Statements 1, 2, 4, 5, and 6 are legal declarations.
A, B, C, D, and F are incorrect because the only illegal declaration is 3; transient
applies only to variable declarations, not to method declarations. As you can see from these other examples, method declarations can be very extensive.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by RAGU KANNAN:
...I won�t agree with the answer 5 (5 � private native void m1 ();).
Because this method is ending with semicolon instead of curly brace.
Pls let me know am i wrong...


native methods use non-Java implementation, and therefore do not require braces.

As stated in the Java Language Specification, Section 8.4.3.4 - native Methods, "The body of a native method is given as a semicolon only, indicating that the implementation is omitted, instead of a block."
[ April 07, 2006: Message edited by: marc weber ]
reply
    Bookmark Topic Watch Topic
  • New Topic