session 5(inheritance) (1)

14
WELCOME TO JAVA TECHNOLOGIES TECHNOLOGIES Srinivas M

Upload: kamandla

Post on 02-Oct-2015

222 views

Category:

Documents


0 download

DESCRIPTION

inheritance

TRANSCRIPT

  • WELCOME TO JAVA TECHNOLOGIESSrinivas M

  • Objective After This session u will be able to do Constructors both default and parameterized .Static variables and Methods.This keywordinheritancesingleMultipleMulti-levelHierarchicalHybrid

  • ConstructorsThe lineplum = new Fruit();invokes a constructor method with which you can set the initial data of an objectYou may choose several different type of constructor with different argument lists eg Fruit(), Fruit(a) ...

  • ConstructorsThese are having following characteristicsIt should be publicIt must have class-name as its name. No return-type.It must be called using class-name.A class can have any no of constructors.

  • Static membersUsed for storing common data for all objects.Declared using static keyword.Have following characteristics.It should be allocated memory when an object is created first time.It should be initialized to zeros If they are integers and nulls if they are strings.No other initialization is allowed. Only Static methods only be allowed.

  • Static methodsSimilar to static variables we can use static methods.These are used for initialization of other static members of a class.Must be called using class-name but not by any object references.It should not allow any other members to be accessed.

  • This keywordJava allows use of similar names to parameters of methods.This is caused to hide members of a class with in that method from being accessing. This is called Instance Member hiding.These can be referenced with in that method using this keyword.

  • This DiagramqlaloriesageclgFruitqcalcFruit f1obj

  • This ExampleClass Fruit{int grams;int cals_per_gram; Fruit(int grams) {this.grams = grams;}int total_calories() {return(grams*cals_per_gram);}}

  • InheritanceThis is an important feature of Object Oriented Programming.Used for implementing concept of Reusability.It is reusing existing things of class with-out redefinition.JAVA implementing this as Inheritance.

    Defined as mechanism of defining new class from another existing class.

  • inheritanceSyntax:Class extends {Intance variables;mthods}

    Here s is Super-classAnd d is sub-class or derived class.

  • inheritanceDue to extends all public members of super class becomes public members of sub-class.So an object of sub class can have access for super-class public members.

    Private members never participate in inheritance.

  • ClassificationTo manage no of classes in java in understandable format JAVA allows arrange classes in several typesThey are SingleMultiple(DOES NOT SUPPORTED BY JAVA)MultilevelHierarchicalHybrid

  • ?