I'm not sure how exactly to phrase my question. So, I have an interface reference and I'm creating a new object. The new object obviously implements said interface. The initial class inherits another class. That sub-class inherits the super class. However, I cannot access data from super class from the main method without casting the reference first. I'll show an example below
public class a {
public int getSomeData1() {
return someData;
}
}
public class b extends a implements someInterface {
// Some behavior.
}
public class c extends b implements someInterface {
// Some behavior.
}
public class Main {
public static void main(String[] args) {
someInterface obj = new b();
obj.someData1(); // I cannot access someData1().
c anotherObj = new c();
c.getSomeData1(); // This works however.
}
}
How can I have obj.someData1() actually get the data from class a rather than casting it to a.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)