can we define Interface inside the class? if yes whts it use & how
or
can we define class inside interface ? if yes whts it use & how
please clear my this point with some example
Thank'x
Printable View
can we define Interface inside the class? if yes whts it use & how
or
can we define class inside interface ? if yes whts it use & how
please clear my this point with some example
Thank'x
Hi,
I think you dont know anything about interfaces, why don't you go through some example in the internet by doing a google search.
Coming to your question, No neither interface can be defined in class nor the vice versa.
An interface has only method and variable definitions which can be implemented by any java class by using "implements" clause.
An interface only declares methods, one has to implement the methods in a class.
An interface is a way to make an object a specific type so that you can pass that object to a method that wants that type as an arg.
For example the Thread class wants an arg of type Runnable. You can have ANY of your classes be of type Runnable by having the class implement Runnable.
Then you have to look at the doc for the interface Runnable, see what methods it requires and write those methods in your class.
In this case, the only method is: public void run() {...
Basically interface is a way to use types to define classes and their methods.