• 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

One more from Khalid

 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Last one for today, also from Khalid. This one is a little easier IMO.
7. Which lines of code are valid declarations of a native method when occurring within the declaration of the following class?

Select all valid answers
A. native public void setTemparature(int kelvin);
B. private native void setTemparature(int kelvin);
C. protected int native getTemparature();
D. public abstract native void setTemparature(int kelvin);
E. native int setTemparature(int kelvin){}

Hope these help. I know they help me trying disect these answers.
Bill
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bill,
I think the answers should be A,B. Actually native methods can be abstract but since the class in this example is not abstract answer D is wrong.E is wrong because it has {} in its declarations. C is wrong because int came before native!
rajani
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right that A and B is correct and you are right on your reasoning for C and E, but not with D.
From the JLS


A compile-time error occurs if a native method is declared abstract.


I actually couldn't remember, so before I went to the JLS, I changed the method so it was abstract and ran the code with the abstract native method and sure enough, compile error saying native methods cannot be abstract.
Bill
[This message has been edited by bill bozeman (edited December 20, 2000).]
 
rajani peddi
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for correcting me Bill. I was having this wrong illusion. I should have compiled before itself!!
rajani
 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bill
1. E is wrong since native methods cant have a method body {}
2 D is wrong because native methods cant be declared as abstract
3. C is wrong because the method signature is incorrect, the return type, void in this case has to be placed directly before the method name.
 
Wanna see my flashlight? How about this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic