Page 224 - PowerPoint Presentation
P. 224
CAVITE STATE UNIVERSITY
T3 CAMPUS
Department of Information Technology COSC 65 – Programming Languages
Systemout.println(student1.getName()); // will give Compile Time Error, because there is
//no such method
System.out.println(Student1.college); // will give Compile Time Error, because college data
//member is private.
// it can’t be accessed from outside the class
QUIZ NO. 9 | Hardcoding: Write a program on a piece of paper that applies ‘Encapsulation’:
Instructions:
1. Create a Class and name it as Account
2. On Class Account, create 4 private data members namely: account_num, name, email
and amount.
3. On Class Account, create 8 methods to access the private data members of the Class
Account namely: setAcc_num(), getAcc_num(), setName(), getName(), setEmail(),
getEmail(), setAmount() and getAmount().
4. On the main class, create at least 1 object that accesses all the data members and
methods of the Class Account.
5. On the main class, create a code that displays the account_num, name, email and
amount of the object1.
Page | 83