Course Hero Logo

CS213 Midterm Notes.pdf - Rutgers University - Software...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 3 out of 7 pages.

Rutgers University - Software Methodology CS213 NotesConstructorA constructor initializes an objectDefault Constructor: ClassName() { }‘new X’ creates object X & ‘X()’ calls the no-arg constructor to initialize itAfter an object is created, but before the constructor is called, fields are initializedwith default values (zero for int, null for object references, etc.)The FIRST statement in a subclass constructor should invoke a superclassconstructor. (Or it should invoke another constructor in the class, with this(...))this() or super() call (if invoked) need to be first statement in constructorA default constructor will ALWAYS CALL a superclass no-arg constructor if anotherexplicit call to super() does not existInheritanceMethod signature:name + params (return type NOT included in signature)Method Overloading:Two methods in a class have the same name but differentnumbers, types, or sequence of parametersMethod Overriding:A method in a subclass has the same signature as in thesuperclassYou can not have a method with the same signature but different return types in thesuper and subclassExample:public class Point { public int x; }public class ColoredPoint extends Point { }A subclass (ColoredPoint) inherits all the fields and methods of its super classDynamic BindingPoint p3 = new ColoredPoint(2, 3, “red”);Static Type: PointDynamic Type (type of instance it points to): Colored PointWhen p3.toString() is called, the overridden version of toString() inColoredPoint will be executedNote: Only members/methods of the Point class can be syntacticallyreferenced by p3Private Fields: private fields in a super class are inherited by the subclass, but arehidden (meaning they can not be accessed without the help of inherited methodse.g. getX() to access private int x;)Static MembersAn instance field of the same name will HIDE inherited static field, HOWEVERinherited static fields are statically bound (to static type), not dynamicallybound (to dynamic type)Static Binding
Point p3 = new ColoredPoint(2, 3, “red”);Static Type: PointDynamic Type (type of instance it points to): Colored Point

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 7 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
Sesh

Newly uploaded documents

Show More

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture