Noobie to Java questions!! :D
Hi all, I'm new to Java and am experiencing some difficulty with this assignment I have...
I have programmed an interface with a bunch of non static methods and now when i extend that program to another class, I can't use the methods because they are non-static! :S What's the catch here?
Thanks in advance!!
-Chansey
Re: Noobie to Java questions!! :D
I'm sure I don't understand your question. Recommended reading: (lines below are links)
The Java™ Tutorials
How To Ask Questions The Smart Way
SSCCE : Java Glossary
db
Re: Noobie to Java questions!! :D
You don't extend an interface... you implement it. To use the methods found inside the interface, you must create an object of that type first. Ex.:
Code :
public class A
{
// here is a non-static, or instanced method
public void doIt()
{
System.out.println("hello world! this is an instanced object.");
}
}
To use/call a non-static method:
Code :
public static void main(String[] args)
{
A myObject = new A(); // instance it
myObject.doIt(); // call the method with the myObject instance
}
Re: Noobie to Java questions!! :D
Ah, but the real question is whether the 'interface' is an interface or a GUI. I suspect the latter.
db
Re: Noobie to Java questions!! :D
Thank you very much for the answers, I hadn't quite understood the whole instancing thing, but helloworld922's post fixed it! I can use my methods now! :D