Z
Zalek Bloom
I am learning Java and here is my problem:
Lets say we have a simple class:
public class Class1
{
final String s1 = "Class1";
public String getMemberS1(){return s1;}
}
Let say we have another simpler class:
public class Class2 extends Class1
{
final String s2 = "Class2";
public String getMemberS2(){return s2;}
}
Now let say we make definitions:
Class1 a = new Class1() ;
Class1 b = new Class2() ;
Now - the variable "b" - it will have properties as Class1 or Class2?
Why?
I wrote a simple program to test it, and it looks that "b" has only a
method and members as Class1, but I wrote:
Class1 b = new Class2() ;
Can somebody explain this?
Thanks,
Zalek
Lets say we have a simple class:
public class Class1
{
final String s1 = "Class1";
public String getMemberS1(){return s1;}
}
Let say we have another simpler class:
public class Class2 extends Class1
{
final String s2 = "Class2";
public String getMemberS2(){return s2;}
}
Now let say we make definitions:
Class1 a = new Class1() ;
Class1 b = new Class2() ;
Now - the variable "b" - it will have properties as Class1 or Class2?
Why?
I wrote a simple program to test it, and it looks that "b" has only a
method and members as Class1, but I wrote:
Class1 b = new Class2() ;
Can somebody explain this?
Thanks,
Zalek