How do I access the object that's been instantiated from the abstract class's subclass in java? -


i able access object that's been instantiated abstract class's subclass. here's example.

// a.java public abstract class {   public int getnewno() {     int newno = <instance of b in example here>.getno() + 2;     return newno;   } }  // b.java public class b extends {   public int getno() {     return 2;   } }  // c.java public class c {   public c(a a) {     system.out.println("the number "+a.getnewno());   } }  // example.java public void main(string args[]) {   b b = new b();   c c = new c(b);   // should print out "the number 4" } 

is possible?

thanks.

public abstract class {     public int getnewno() {         int newno = getno() + 2;         return newno;     }      abstract int getno(); } 

will job.


Comments