Inheritance in Java

Posted by stevebot on Stack Overflow See other posts from Stack Overflow or by stevebot
Published on 2010-05-14T14:14:46Z Indexed on 2010/05/14 14:24 UTC
Read the original article Hit count: 298

Filed under:
|

If I have an abstract class in java named Foo and it has an implementor named Bar then I want to know the following.

lets say Foo looks something like

public abstract class Foo {

  Service serviceFoo

  ...

}

And Bar is

public class Bar extends Foo {
...
}

Also, lets assume I have an instance with Foo, named foo, currently that has serviceFoo instantiated

If I then declare:

Foo foo = new Bar();

will this create a a new instance of Bar that has serviceFoo instantiated or not? E.g. will that field be inherited and instantiated or just inherited?

© Stack Overflow or respective owner

Related posts about java

Related posts about inheritance