I have a problem. Why does the program ask me for the variable "i" three times, and how could I fix it?
Sorry for making it so long, but I don't know any other way of illustrating my problem..
import java.util.*;
public class Test
{
public static void main (String args[])
{
Testing1 T;
T = new Testing1();
T.Testing1Method();
Testing2 T2;
T2 = new Testing2();
T2.Testing2Method();
Testing3 T3;
T3 = new Testing3();
T3.Testing3Method();
}
}
//Testing1.java
import java.util.*;
public class Testing1
{
Scanner scan = new Scanner(System.in);
int i = scan.nextInt();
public void Testing1Method()
{
System.out.println("Test1= " + i);
Testing2Method();
}
public void Testing2Method()
{
}
}
//Testing2.java
public class Testing2 extends Testing1{
public void Testing2Method(){
super.Testing2Method();
System.out.println("Test2 " + i);
Testing3Method();
}
public void Testing3Method()
{
}
}
//testing3.java
public class Testing3 extends Testing2
{
public void Testing3Method()
{
super.Testing3Method();
System.out.println("Test3 " + i);
}
}
Thanks