Dale Roberts Introduction to Java - Access Specifiers Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School of Science, IUPUI
Dale Roberts 2 Access Modifiers public and private private keyword Used for most instance variables private variables and methods are accessible only to methods of the class in which they are declared Declaring instance variables private is known as data hiding public keyword Exposes variables or methods outside the Class. Declaring public methods is know as defining the class’ public interface. Return type Indicates item returned by method Declared in method header
Dale Roberts 3Outline GradeBo ok.java Instance variable courseName set method for courseName get method for courseName Call get method
Dale Roberts 4Outline GradeBo okTest.j ava (1 of 2) Call get method for courseName
Dale Roberts 5Outline GradeBo ok.java (1 of 2) Constructor to initialize courseName variable
Dale Roberts 6Outline GradeBook.j ava (2 of 2)
Dale Roberts 7Outline GradeBookT est.java Call constructor to create first grade book object Create second grade book object
Dale Roberts 8Outline GradeBo okTest.j ava Call constructor to create first grade book object Create second grade book object
Dale Roberts Acknowledgements Pearson Education, Lewis and Loftus. Deitel, Java How to Program /language.impl.overview.pdf /language.impl.overview.pdf