• 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

how can we import a package ?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i imported a package simulation , and in this package there is an iterface. The methods inside this interface are of type public. the only problem i have is when i import this package (like this ==> import Simulation.* and i want to use the methods of the interface such ==> Simulation.negExp(avrg); it gives an error at the compilation time which is :
non-static method negExp(double) cannot be referenced from a static context.
does it mean that the methods declared in the interface should be static ?
plz help me
thanks in advance
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, you cannot use methods of an interface without some class implementing all the abstract methods defined in the interface. Also, if you have a static method inside of a class [such as public static void main(String[] args)] you cannot use any instance members, variables or methods, within the static method. The reason for that is all static members are resolved at compile time whereas all instance members are polymorphic and resolved at runtime.
 
Salma Benmkhtar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes , u r right , i need to write some code in each method.
i removed the static and the interface.
it works for the moment.
thanks a lot
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Salma --
We ain't got too many rules round these parts, but we do have our naming policy which requires you to use both your first and last names. Please head over here and fix your display name, pronto! Thanks, pardner.
 
Salma Benmkhtar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry , I m new user and i didn't read the naming policy.
here i change it.

 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!
 
Do not threaten THIS beaver! Not even with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic