CSE 8B Lecture Notes - Lecture 7: Downcasting, Member Variable, Subtyping

65 views3 pages

Document Summary

Called when an object of that type is created: new operator creates a new object this() same class ctor invocation super() immediate superclass ctor invocation. Can have access modifiers ie. public, private, etc. Cannot have method modifiers ie. static, final, etc. Class with no ctor definitions compiler automatically calls default no-arg ctor. Constructor body this(args) calls same class ctor: super(args) calls super class ctor. Can initialize super (cid:272)lass"s private instan(cid:272)e varia(cid:271)les: else, compiler calls no args constructor. If the class extends from another class, then the compiler will call super() Error if super class does not have a no-arg ctor. Superclass ctors execute first, then subclass ctors on way out this. Explicitly states whether or not to use instance members or local variables/ parameters: public class a { Public a (int var) { var = var; Public int getvar() { return this. var: // in main. // this code does not alter member variable var.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents