Transcript
  • OBJECTS AND CLASSES Object Oriented Programming

    Advanced Object-Oriented Concepts (Part 1)

  • Objects and ClassesClassification of ObjectsPhysicalobjects which can be seen or touchedConceptualobjects which cant be touched but they exists

    *Objects and Classes

    Advanced Object-Oriented Concepts (Part 1)

  • Objects and ClassesRelationship between an object and a class

    Object is -- an an - instance instance - of ClassEg. Juan Dela Cruz is an instance of Person

    *Objects and Classes

    Advanced Object-Oriented Concepts (Part 1)

  • VariablesKinds of VariablesFields - member variables of a classLocal Variables variables declared in a method or block of codeParameters variables used in method

    *Objects and Classes

    Advanced Object-Oriented Concepts (Part 1)

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

    *Objects and Classes

    Advanced Object-Oriented Concepts (Part 1)

  • Declaring Member Variables

    The static keyword is used to indicate that a variable is a static variable.

    *Objects and Classes

    Advanced Object-Oriented Concepts (Part 1)

  • 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

    *Objects and Classes

    Advanced Object-Oriented Concepts (Part 1)

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

    Advanced Object-Oriented Concepts (Part 1)*

    Advanced Object-Oriented Concepts (Part 1)

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

    Advanced Object-Oriented Concepts (Part 1)*

    Advanced Object-Oriented Concepts (Part 1)

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

    Advanced Object-Oriented Concepts (Part 1)*

    Advanced Object-Oriented Concepts (Part 1)

  • 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)

    Advanced Object-Oriented Concepts (Part 1)*

    Advanced Object-Oriented Concepts (Part 1)

  • 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)*

    Advanced Object-Oriented Concepts (Part 1)

  • 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

    Advanced Object-Oriented Concepts (Part 1)*

    Advanced Object-Oriented Concepts (Part 1)

  • 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

    Advanced Object-Oriented Concepts (Part 1)*

    Advanced Object-Oriented Concepts (Part 1)

  • 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)*

    Advanced Object-Oriented Concepts (Part 1)

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

    Advanced Object-Oriented Concepts (Part 1)*

    Advanced Object-Oriented Concepts (Part 1)

  • 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

    Advanced Object-Oriented Concepts (Part 1)*

    Advanced Object-Oriented Concepts (Part 1)

    *


Top Related