CMSC 131A Study Guide - Midterm Guide: Javadoc, Object Copying, Call Stack

103 views37 pages

Document Summary

The name of the constructor(s) need(s) to match the name of the class and have no return type. Instance fields appear inside each object while static fields are shared and live inside metaspace. Good style keeps fields private and provides getters and setters as needed. Keep track of how many have been created. Static vs instance fields file: student. java public class student { public class student { //a reference public string uid; private float semesterscore; // these two methods. private static string convertinttostring(int inval) private static int convertuidtoint(string inval) In this case, the standard ones to provide are: setname(string) getname() setnickname(string) getnickname() setuid(int) getuid() setscore(int) getscore() Code: setters and getters public void setname(string namein){ Nickname= new stringbuffer(nickin); public void setuid(int uidin){ Within an instance method you can optionally refer to the object that invoked this method using the automatically created local reference this. public void setname(string namein){

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

Related Documents