• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

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: 24203
44
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: 24203
44
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!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic