G
Gary
Hi Again, I have written the program below and it prints out "Gary1"
and "Gary2". My question is why does this work. The variable tc2 is an
instance of the class with member variable that holds "Gary2". The
variable tc1 is an interface, not a class, but it seems to be behaving
like an instance of class. I know it behaves this way but I do not
know why. I would have expected that tc1 would have been an interface
and therefore have no implementation.
Thank you
Gary Hindrew
package mypackage7;
public class Class6
{
public interface TestInterface
{
public String getName();
}
public static class TestClass implements TestInterface
{
private String s;
public TestClass(String s)
{
this.s=s;
}
public String getName()
{
return s;
}
}
public static void main(String[] args)
{
TestInterface tc1=new TestClass("Gary1");
TestClass tc2=new TestClass("Gary2");
System.out.println(tc1.getName());
System.out.println(tc2.getName());
}
}
and "Gary2". My question is why does this work. The variable tc2 is an
instance of the class with member variable that holds "Gary2". The
variable tc1 is an interface, not a class, but it seems to be behaving
like an instance of class. I know it behaves this way but I do not
know why. I would have expected that tc1 would have been an interface
and therefore have no implementation.
Thank you
Gary Hindrew
package mypackage7;
public class Class6
{
public interface TestInterface
{
public String getName();
}
public static class TestClass implements TestInterface
{
private String s;
public TestClass(String s)
{
this.s=s;
}
public String getName()
{
return s;
}
}
public static void main(String[] args)
{
TestInterface tc1=new TestClass("Gary1");
TestClass tc2=new TestClass("Gary2");
System.out.println(tc1.getName());
System.out.println(tc2.getName());
}
}