FUNDAMENTAL QUESTION 2:
From: Gary (garyjhindrew_at_hotmail.com)
Date: 11/29/03
- Next message: Thomas Schodt: "Re: compress a short string to an even shorter string"
- Previous message: Gary: "FUNDAMENTAL QUESTION 1:"
- Next in thread: VisionSet: "Re: FUNDAMENTAL QUESTION 2:"
- Reply: VisionSet: "Re: FUNDAMENTAL QUESTION 2:"
- Reply: hexathioorthooxalate: "Re: FUNDAMENTAL QUESTION 2:"
- Reply: Bjorn Abelli: "Re: FUNDAMENTAL QUESTION 2:"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Nov 2003 02:28:19 -0800
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());
}
}
- Next message: Thomas Schodt: "Re: compress a short string to an even shorter string"
- Previous message: Gary: "FUNDAMENTAL QUESTION 1:"
- Next in thread: VisionSet: "Re: FUNDAMENTAL QUESTION 2:"
- Reply: VisionSet: "Re: FUNDAMENTAL QUESTION 2:"
- Reply: hexathioorthooxalate: "Re: FUNDAMENTAL QUESTION 2:"
- Reply: Bjorn Abelli: "Re: FUNDAMENTAL QUESTION 2:"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|