Initializing and using Interfaces in Java? -
first of all, learned that:
- you cannot instantiate interface
- an interface doesn't implement functions
after seeing following java code:
public class myclasstest { public static void main(string[] args) { // string charsequence? charsequence c = "java"; system.out.println(c); system.out.println(c.length()); } }
i confused when learned charsequence
interface
how can use interface object , initialize it?
why
charsequence
implementslength
function if interface?
"java"
instance of string
class, implements charsequence
interface, includes implementing length()
method. therefore can assign charsequence
variable.
a variable type interface can assigned references instances (objects) of classes implement interface.
Comments
Post a Comment