• Post Reply Bookmark Topic Watch Topic
  • New Topic

how can we import a package ?  RSS feed

 
Salma Benmkhtar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!