M
mdinino
In the following exampe, if I want to set the global variables of
AbstractTest in ConcreteTest, I need brackers (pointed out with "===>")
even though I am initalizing global variables in a global scope. Can
anybody tell me why the Java compiler requires this?
package Test;
public abstract class AbstractTest
{
protected int x1;
protected int x2;
protected int x3;
public void show()
{
System.out.println("x1 is: " + x1);
System.out.println("x2 is: " + x2);
System.out.println("x3 is: " + x3);
}
}
package Test;
public class ConcreteTest extends AbstractTest
{
===> {
x1 = 5;
x2 = 7;
x3 = 13;
===> }
}
package Test;
public class Test
{
public static void main(String[] args)
{
ConcreteTest myConTest = new ConcreteTest();
myConTest.show();
}
}
AbstractTest in ConcreteTest, I need brackers (pointed out with "===>")
even though I am initalizing global variables in a global scope. Can
anybody tell me why the Java compiler requires this?
package Test;
public abstract class AbstractTest
{
protected int x1;
protected int x2;
protected int x3;
public void show()
{
System.out.println("x1 is: " + x1);
System.out.println("x2 is: " + x2);
System.out.println("x3 is: " + x3);
}
}
package Test;
public class ConcreteTest extends AbstractTest
{
===> {
x1 = 5;
x2 = 7;
x3 = 13;
===> }
}
package Test;
public class Test
{
public static void main(String[] args)
{
ConcreteTest myConTest = new ConcreteTest();
myConTest.show();
}
}