Chapter5_2-Methods

Studentname has the course course2coursecode page

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: .studentName= “Majed AlKebir“; //Create and assign values to course2 course2 = new Course( ); course2.courseCode= “CSC107“; course2.studentName= “Fahd AlAmri“; System.out.println(course1.studentName + " has the course “+ course1.courseCode); System.out.println(course2.studentName + " has the course “+ course2.courseCode); } } Page 22 Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP Getters The object point of view • Are operations performed by the object returning to outsiders data retrieved from the object state. :Y (Client) The user point of view • Are services called from outside allowing to retrieve data from the object state. object:X public private Data Data Getters are: •Public •With no parameters •With return value Getters Page 23 Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP Template for Getters public class ClassName { private dataType1 attribute1; ... private dataTypen attributen; ... public dataType1 getAttribute1() { return attribute1; } ... public dataTypen getAttributen() { return attributen; } ... } Page 24 Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP Setters The object point of view The user point of view • Are operations • Are services used by performed by the outsiders allowing to object allowing to provide to the object receive and store in the the data that should object state the data be stored in the provided by outsiders. object state. :Y (Client) object:X public private Data Data Setters are: •Public •With 1 parameter •With no return value Setters Page 25 Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP Template for Setters public class ClassName { private dataType1 attribute1; ... private dataT...
View Full Document

This document was uploaded on 03/03/2014.

Ask a homework question - tutors are online