02 Objects and Classes

Download 02 Objects and Classes

Post on 14-Nov-2015

2 views

Category:

Documents

0 download

Embed Size (px)

DESCRIPTION

Object Oriented Programming

TRANSCRIPT

<ul><li><p>OBJECTS AND CLASSES Object Oriented Programming</p><p>Advanced Object-Oriented Concepts (Part 1)</p></li><li><p>Objects and ClassesClassification of ObjectsPhysicalobjects which can be seen or touchedConceptualobjects which cant be touched but they exists</p><p>*Objects and Classes </p><p>Advanced Object-Oriented Concepts (Part 1)</p></li><li><p>Objects and ClassesRelationship between an object and a class</p><p>Object is -- an an - instance instance - of ClassEg. Juan Dela Cruz is an instance of Person</p><p>*Objects and Classes </p><p>Advanced Object-Oriented Concepts (Part 1)</p></li><li><p>VariablesKinds of VariablesFields - member variables of a classLocal Variables variables declared in a method or block of codeParameters variables used in method </p><p>*Objects and Classes </p><p>Advanced Object-Oriented Concepts (Part 1)</p></li><li><p>Declaring Member VariablesCoding guidelines when declaring member variablesDeclare all instance variables on the top of the class declaration.Declare one variable for each line.Instance variables should start with small letter.Use an appropriate data type for each declared variable.Declare instance variables as private so that only class methods can access them directly. </p><p>*Objects and Classes </p><p>Advanced Object-Oriented Concepts (Part 1)</p></li><li><p>Declaring Member Variables</p><p>The static keyword is used to indicate that a variable is a static variable.</p><p>*Objects and Classes </p><p>Advanced Object-Oriented Concepts (Part 1)</p></li><li><p>Access ModifiersPublicspecifies that class members are accessible to anyone, both inside and outside the class Private specifies that the class members are only accessible by the class they are defined in Protectedspecifies that the class members are accessible only to methods in that class and the subclasses of the classDefaultspecifies that only classes in the same package can have access to the class variables and methods </p><p>*Objects and Classes </p><p>Advanced Object-Oriented Concepts (Part 1)</p></li><li><p>Declaring MethodsA method is a self-contained block of program code that is similar to a procedure. A method is a sequence of instructions that a class or an object follows to perform a task. To execute a method, you invoke or call it from another method.</p><p>Advanced Object-Oriented Concepts (Part 1)*</p><p>Advanced Object-Oriented Concepts (Part 1)</p></li><li><p>Declaring MethodsNaming a MethodMethod names should be a verb in lowercase or a multi-word name that begins with a verb in lowercase, followed by adjectives, noun, etc. In multi-word names, the first letter of each of the second and following words should be capitalized. </p><p>Advanced Object-Oriented Concepts (Part 1)*</p><p>Advanced Object-Oriented Concepts (Part 1)</p></li><li><p>Methods that Return ValuesA methods return type can be primitive types like int, double, char, etc., as well as class types. A methods return type is declared in its method declaration. Within the body of the method, the return statement is used to return the value.A method that does not return a value is declared void.</p><p>Advanced Object-Oriented Concepts (Part 1)*</p><p>Advanced Object-Oriented Concepts (Part 1)</p></li><li><p>MethodsAccessor Methodsmethod that is used to read values from member fields (instance/static) returns the value of the field Mutator Methodsmethod that is used to write or change the value of member fields (instance/static) </p><p>Advanced Object-Oriented Concepts (Part 1)*</p><p>Advanced Object-Oriented Concepts (Part 1)</p></li><li><p>Method Overloadingobject-oriented technique that lets you define several different versions of a method, all with the same name but each with a different argument or parameter listAdvanced Object-Oriented Concepts (Part 1)*</p><p>Advanced Object-Oriented Concepts (Part 1)</p></li><li><p>Constructorsspecial type of method that establishes or creates a new object have the same name as their class and have no return value in their declaration can only be called by using the new operator during class instantiation </p><p>Advanced Object-Oriented Concepts (Part 1)*</p><p>Advanced Object-Oriented Concepts (Part 1)</p></li><li><p>ConstructorsDefault Constructor the constructor without any arguments or parameterscreated automatically by the Java compiler for any class created whenever you do not write your own constructor </p><p>Advanced Object-Oriented Concepts (Part 1)*</p><p>Advanced Object-Oriented Concepts (Part 1)</p></li><li><p>ConstructorsConstructors are used after you have instantiated an object.The new keyword is the key to instantiating an object. Advanced Object-Oriented Concepts (Part 1)*</p><p>Advanced Object-Oriented Concepts (Part 1)</p></li><li><p>The this Keywordkeyword in Java that can be used in instance methods (or a constructor) to refer to the object on which the currently executing method has been invoked used to access the instance variables shadowed or obscured by the parametersthis.</p><p>Advanced Object-Oriented Concepts (Part 1)*</p><p>Advanced Object-Oriented Concepts (Part 1)</p></li><li><p>Packagesnamed collection of classes Javas means of grouping related classes and interfaces together in a single unitby default, all Java programs import the :java.lang.* package</p><p>Advanced Object-Oriented Concepts (Part 1)*</p><p>Advanced Object-Oriented Concepts (Part 1)</p><p>*</p></li></ul>