• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

doubt in K&B book.. pg:135

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
doubt in K&B book.. pg:135 .... 5th question..

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(); //how come this is correct declaration..??
6.static final synchronized protected void m1(){}


A.1
B.2
c.3
d.4
e.5
f.all of them.

the answer is E.5 ... i dont know how... someone help me out...

i dont know how is that 5th option is right...

private native void m1();..... how come???
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This compiles:


Why do you think it should not?
[ June 24, 2006: Message edited by: Barry Gaunt ]
 
vignesh hariharan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
could you please explain me how this works.. only this native method works i think.. please sir... explain slightly more about this..

i thought if it is a private method and if the body is undefined that is,if it is abstract, then i thought it should be allowed to override in the class which extends it(anyway we are not extending it here).. i thought it will throw an error saying the class is not defined abstract.. but it is compiling fine.. how come??
[ June 24, 2006: Message edited by: vignesh hariharan ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The method is not specified as being abstract nor is the class an abstract class. You are telling me you are thinking this and thinking that... but have you looked up in a book about java what the native keyword means?

Here's what the Java Language Specification 8.4.3.4 says.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vighnesh, plz read the questions correctly. It is asking "How many... "
The answer is 5 i.e. 5 of them are correct, not that only Option 5th is correct.

The incorrect one is

transient private native void m1(){}

transient is invalid modifier for method.

Hope, it helps.
 
vignesh hariharan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the link given by barry gaunt was really helpful.. thank you.. and ashish i knew that the answer is five of them are legal..and not the fifth one alone.. i think u have misinterpreted.. anyway thanks ....
 
reply
    Bookmark Topic Watch Topic
  • New Topic