Your logic works fine. The problem is that you have many syntax error in your code. Try to use the following and it will work:
public class Parent {
public String name1="Tom",name2="John",name3="Harry";
public static void main(String[] args)throws Exception{
Child pere = new Child();
pere.introduce();
}
}
class Child{
public static String name1_i,name2_i,name3_i;
public static void introduce(){
Parent variable = new Parent();
String[] names_i = {name1_i,name2_i,name3_i};
String[] names = {variable.name1 , variable.name2 , variable.name3 };
System.out.println("");
System.out.println("");
//names_i[0] = name1_i = names[0];
names_i[0] = names[0];
//name1_i = names_i[0];
System.out.println(names_i[0]);
System.out.println(name1_i + " <-- Expecting Tom");
}
}
Once you become more familiar with Java (syntax, packaging and other basic aspect of the language) then try to get a good book on Object Oriented (OO) programming. At the moment your code doesn't comply with the OO standards.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…