java - Get the right field from an abstract class hierarchy? -


i have abstract class a

public abstract class a{     private int x;     public void dosomethingtox{...};     public int getx(){      return x;     } 

i have 7 classes extend a, each of 7 implement dosomethingtox in same way, defined in class a. if class b extends a, , call b.dosomethingtox(), , call b.getx(), b's x value or a's?

in real program have arraylist of objects

arraylist<a> list; 

and call:

  list.add(new b());    list.get(index).dosomethingtox();    list.get(index).getx(); 

will a's x or b's?

if don't override getx() on extended classes x a.

if override getx() value returned on overrides method.

example:

a = new b(); a.getx(); b b = new b(); b.getx(); 

all above lines return value of getx() overridden on class b.

if method not overriden on class b value defined on class a.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -