When instantiating a (sub)Class, is there any difference in what “type” you declare the object as?
问题 Say I have a Class called ParentClass and a Class called ChildClass The ParentClass is abstract and the ChildClass extends the ParentClass per Java terminology. Furthermore, the ParentClass has a constructor which takes an int as a parameter. Now in another class I want to instantiate the ChildClass . I have tried the two below ways: ChildClass obj1 = new ChildClass(5) ParentClass obj2 = new ChildClass(5) Java allows me to use any of the two above ways. My question is, is there actually any