Page 288 - PowerPoint Presentation
P. 288

CAVITE STATE UNIVERSITY
                               TRECE MARTIRES CITY CAMPUS
                               Department of Information Technology            DCIT 111 - Advanced Programming


                  // A Java class which has only setter method / THIS IS A WRITE-ONL CLASS
                  class Student {
                        private String College;
                               public void setCollege(String college) {
                                       College = college;
                               }
                  }  // now you can’t get the value of the college, you can only change the value of college data
                  member

                  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 7. 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.














































                                                                                                            64
   283   284   285   286   287   288   289   290   291   292   293