Hello guys, I just started self teaching and encounter a problem that requires me to access a variable from a different class.
Here's a shortened version of what I have so far...
abstract public class A { //nothing yet } public class B extends A { protected int num; public int getNum(){...} public void setNum(int x){...} } abstract public class XYZ { protected A[] myList = new A[10]; // this is an array of instances of class A } public class XYZ_2 extends XYZ { public int small() { // here I want to be able to compare each element in 'myList' to find the smallest number // but right now I don't even know how to access the variable 'num'... int x = this.myList[0].num //attempt 1 int x = this.myList[0].getNum(); //attempt 2 int x = myList[0].num //attempt 3 int x = myList[0].getNum(); //attempt 4 // the error says "XYZ_2.java:141:error:cannot find symbol" // "int x = this.myList[0].getNum();" // ^ // "symbol: method getNum();" // "location: class A" // "1 error" } }
Any advice is HUGELY appreciated..!!