CS 106A Lecture Notes - Lecture 18: Instance Variable

41 views3 pages

Document Summary

Class body: name is in upper camel case (mystudent, doesn"t always have to extend superclass b. i. By default, extends object : file name for class has same name. Classname. java: class body has methods, variables, constants, project, right click myclasses, click new, put name of class, click finish, example, student a. i. /* private instance variables */ private string name; private int id; private double unitsearned; /* sets name and id for student*/ public student ((string studentname, int studentid) { name = studentname; Student mehran = new student ( mehran sahami , 38000000); Mehran. setunits(3); printunits(mehran): tips, all instance variables should be private; so no one can come in and modify them directly; cannot be directly accessed outside class a. i. Stores state of object: for constructor b. i. Name of constructor name = name of class b. ii. Responsible for initializing object: you can"t have parameters the same as instance variables c. i.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents