LectureStaticOverloadingInClass - Counter example - How...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Counter example - How static variables differ from instance variables Static variable (class variable) - only one copy in existence - not per object Instance variable - one copy for each object What happens when you assign one reference to another public class ClassRoster { private String[] firsts; private String[] lasts; public ClassRoster(int numStudents) { // allocate our array } public ClassRoster(String[] firsts, String[] lasts) { // assign my firstName array to firstNames // this.firsts = firsts; this.firsts = new String[firstNames.length]; // copy elements from one array to the other // assign my lastName array to lastNames this.lasts = lasts; } } I can provide both constructors - method overloading - two methods with the SAME name but different input parameters (types) The act of figuring out which of several overloaded methods is being called, is called binding. The types of the input arguments are used to bind the method call to the method being called. Every class has a default constructor which is used ONLY if you do not
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

LectureStaticOverloadingInClass - Counter example - How...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online