• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

doubt on final, native, abstract keywords

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question 1:

Can we use final keyword with a constructor?

class Test{
final Test(){System.out.println("constructor");}
}

compilation error: modifier final not allowed here.

Question 2:

abstract class Test
{
native abstract void mymethod();
}

Test.java:3: illegal combination of modifiers: abstract and native
native abstract void mymethod();
^

can any one of you tell me the reason.

Thanx in advance
Naresh
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Constructors cannot be inherited ,
thats why, we cannot declare them final.

correct me if I am wrong
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Know the difference between scope modifiers ( ie what kind of scope : public, private, protcted ) and

[variable, methos, class] modifiers ( that provides the kind of 'nature'. there are many static, final, abstract, native etc..... and you can't use these final anywhere other than with Class, Variables, Methods )..

For native : it is used for JNI to call like C-functions.. with abstract makes a bit confusion ?? don't know !!
 
Ranch Hand
Posts: 502
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Can we use final keyword with a constructor?


" final " is meaningless with constructors, because constructors cannot be overridden.

Question 2:



When you use " native ", it means method is implemented using platform dependent language code ((e.g.) C). This is talking about implementation details, but abstract is used for non implemented methods. So, using abstract with native is meaningless.

- HTH
 
today's feeble attempt to support the empire
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic