CSE 8B Lecture 8: Polymorphism and Abstract Classes
Document Summary
If a class has no constructor, compiler will automatically use default (no-arg) constructor. Constructor body: first line this (args) same class ctor call super (args) super class ctor call, else, compiler inserts as first statement super(); A super class type reference can refer to a subclass type object. Super class types: specify commonality in attributes and behaviors, all types derive from super class type inherit the capabilities of the super class. Sub class types: adds attributes and behaviors specific to sub type, override super class behaviors to customize to sub type. When running the program, the methods that are run are from the actual object type. When compiling, the compiler looks for the method declaration in the declared object type. Casti(cid:374)g cha(cid:374)ges co(cid:373)piler"s (cid:448)ie(cid:449) of type of refere(cid:374)ce, not object. Syntax for assigning sub class type to super class type: super superref = new sub(); Syntax for assigning super class type to sub class type: sub subref = (sub)superref;