CHAPTER 5 DECLARING  CLASSES  , ENCAPSULATION ,  INHERITANCE ,  POLYMORPHISM ,  ABSTRACT  AND  EXCEPTION HANDLING
PAG WALA ENCAPSULATION MAWAWALA ANG  DANGAL  AT  INTEGRIDAD  NG PROGRAM
ENCAPSULATION <ul><li>Encapsulation  is the ability of an object to be a container (or capsule) for related  properties  (...
DATA HIDING <ul><li>Data hiding  is the ability of objects to shield variables from external access. It is a useful conseq...
CLASS
 
 
METHODS
 
CONSTRUCTOR
 
Constructors are used to initialize instance variables  There is always at least one constructor in every class. If a prog...
this <ul><li>EVERY OBJECT CAN ACCESS A REFERENCE TO ITSELF </li></ul>
 
 
Final  items cannot be modified. In the case of classes and methods, it means they cannot be extended or overridden, respe...
 
 
 
 
TAGA CONTROL NG ACCESS ALSO  DEFINE THE BOUNDARY  OF AN OBJECT WITH IN THE PACKAGE LANG PUWEDE MAG EXPLORE
 
 
 
 
 
 
 
COMPOSITION <ul><li>A CLASS CAN HAVE REFERENCES TO OBJECT OF OTHER CLASSES AS MEMBER. </li></ul><ul><li>set  – modify the ...
Main Class
SubClass
PRIVATE STRING NAME +setName(name:String):void +setGrade(grade:double):void () – attributes or parameter argument
This class declaration. The class body ( the area between the braces) contains all  The code that provides for the objects...
<ul><li>Field declarations are composed of 3 components in order: </li></ul><ul><li>Zero or more modifiers such as public ...
 
 
 
 
toString <ul><li>The  toString  method is widely implemented. It provides a simple, convenient mechanism for debugging cla...
 
 
 
 
 
 
 
 
 
 
 
 
EXAMPLE OF INHERITANCE
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
INHERITANCE <ul><li>indicates the capability of a class to be  inherited  or extended by other classes.  abstract  classes...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
INTRODUCING FINAL VERSION OF STUDENT RECORD APPLICATION BY  ENGINEER JESS DALE DELA CRUZ
 
 
 
 
 
 
 
STUDENT
 
 
 
 
 
 
 
 
 
 
 
TEACHER
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Upcoming SlideShare
Loading in …5
×

Chapter 5 declaring classes & oop

692 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
692
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
32
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Chapter 5 declaring classes & oop

  1. 1. CHAPTER 5 DECLARING CLASSES , ENCAPSULATION , INHERITANCE , POLYMORPHISM , ABSTRACT AND EXCEPTION HANDLING
  2. 2. PAG WALA ENCAPSULATION MAWAWALA ANG DANGAL AT INTEGRIDAD NG PROGRAM
  3. 3. ENCAPSULATION <ul><li>Encapsulation is the ability of an object to be a container (or capsule) for related properties (ie. data variables) and methods (ie. functions). Older languages did not enforce any property/method relationships. This often resulted in side effects where variables had their contents changed or reused in unexpected ways and spaghetti code that was difficult to unravel, understand and maintain. Encapsulation is one of three fundamental principles in object oriented programming . </li></ul>
  4. 4. DATA HIDING <ul><li>Data hiding is the ability of objects to shield variables from external access. It is a useful consequence of the encapsulation principle. Those variables marked as private can only be seen or modified through the use of public accessor and mutator methods. This permits validity checking at run time. Access to other variables can be allowed but with tight control on how it is done. Methods can also be completely hidden from external use. Those that are made visible externally can only be called by using the object's front door (ie. there is no 'goto' branching concept). </li></ul>
  5. 5. CLASS
  6. 8. METHODS
  7. 10. CONSTRUCTOR
  8. 12. Constructors are used to initialize instance variables There is always at least one constructor in every class. If a programmer does not define a constructor, the compiler automatically creates one.
  9. 13. this <ul><li>EVERY OBJECT CAN ACCESS A REFERENCE TO ITSELF </li></ul>
  10. 16. Final items cannot be modified. In the case of classes and methods, it means they cannot be extended or overridden, respectively. Native methods are implemented using a language other than Java, usually C or C++. Synchronized methods can be executed by only one thread at a time. Volatile fields are eliminated from certain compiler optimizations regarding references to them. Transient fields are ones that will not be saved when an object is serialized. Static items can be referenced using the name of the class in which they are defined to access them. They are not associated with class instances, although they can be referenced using instance variables. Final items cannot be modified. In the case of classes and methods, it means they cannot be extended or overridden, respectively. MODIFIERS/ QUALIFIERS
  11. 21. TAGA CONTROL NG ACCESS ALSO DEFINE THE BOUNDARY OF AN OBJECT WITH IN THE PACKAGE LANG PUWEDE MAG EXPLORE
  12. 29. COMPOSITION <ul><li>A CLASS CAN HAVE REFERENCES TO OBJECT OF OTHER CLASSES AS MEMBER. </li></ul><ul><li>set – modify the variable value to ensure the new value is approximate for that data item. </li></ul><ul><li>get - control how the client can access the variable. </li></ul>
  13. 30. Main Class
  14. 31. SubClass
  15. 32. PRIVATE STRING NAME +setName(name:String):void +setGrade(grade:double):void () – attributes or parameter argument
  16. 33. This class declaration. The class body ( the area between the braces) contains all The code that provides for the objects created from the class: constructors for Initializing new objects, declaring for the fields that provide the state of the class and its object, and methods to implement the behavior of the class and its objects.
  17. 34. <ul><li>Field declarations are composed of 3 components in order: </li></ul><ul><li>Zero or more modifiers such as public and private </li></ul><ul><li>The field’s type. </li></ul><ul><li>3. The field’s name. </li></ul>
  18. 39. toString <ul><li>The toString method is widely implemented. It provides a simple, convenient mechanism for debugging classes during development. It is also widely used for logging, and for passing informative error messages to Exception constructors and assertions. When used in these informal ways, the exact format of toString is not part of the contract of the method, and callers should not rely on the exact format of the returned String. The toString method may occasionally be used more formally, however. An example is a simple mechanism for translating an object into a well-defined textual form (toString) and back again (valueOf). In this case, it is particularly important to specify the exact form of such text in javadoc. </li></ul><ul><li>When implementing toString, StringBuilder can be used instead of the + concatenation operator, since the StringBuilder.append operation is slightly faster. </li></ul>
  19. 52. EXAMPLE OF INHERITANCE
  20. 71. INHERITANCE <ul><li>indicates the capability of a class to be inherited or extended by other classes. abstract classes must be extended and final classes can never be extended by inheritance. The default (ie. omitted) indicates that the class may or may not be extended at the programmers discretion. </li></ul><ul><li>Class_name has initial letter capitalized by Java convention. </li></ul><ul><li>The third option of extends is described in the tutorial on inheritance . </li></ul><ul><li>The fourth option of implements is described in the tutorial on interfaces . </li></ul>
  21. 117. INTRODUCING FINAL VERSION OF STUDENT RECORD APPLICATION BY ENGINEER JESS DALE DELA CRUZ
  22. 125. STUDENT
  23. 137. TEACHER

×