COMP 202 Lecture Notes - Lecture 17: Instance Variable, Class Variable
jc123 and 40170 others unlocked
100
COMP 202 Full Course Notes
Verified Note
100 documents
Document Summary
Entire class (one per class) Instance of a class (one per object/instance) How to call (methods) from outside the class. How to reference (data) from outside the class. A method that is executed when a new object of that class is created. The syntax for constructors is similar to that of other methods, except: The name of the constructor method mustbe the same as the name of the class. It has no return type (not even void!) // some data declared here. ; public classname(){ Comp202 lecture 17 more on static vs non static. Recap writing the blueprint: public class classname { Static v non static recap: To prevent someone from making an instance in your class, you can make the constructor private: private classname(){ We have seen that the value of a final variable cannot be changed after it has been assigned. Final variables must be initialized! (otherwise compile- time error)