Sunday, November 26, 2017

OOP CONCEPTS

POLYMORPHISM
  • Ability to identify a function to run.
  • One name many forms.(some object/function behaving as many forms)

1)Compile time(Overloading)
  • Also called method and operator overloading.
  • Method with same name,but different signature,signature means:
  1.  No. of parameters
  2. Type of parameters
  3. Order of parameters

2)Run-time(Overriding)
  • Method of base class is re-defined in the derived class.
  • Method with same name,same signature and exactly the same return type.



INHERITANCE
  • Child class allows to inherit properties from its parent class(extends keyword).
  • Access only public/protected.


Multiple inheritance
  • Child class inherit properties from multiple classes.
  • Java does not allow extend multiple classes.
  • Problem with multiple inheritance: 

If multiple parents have methods with same name,then at run at run time difficult to decide for the compiler,which method to execute.

  • To overcome this problem,Java allows to implement multiple interfaces.




ABSTRACTION
  • Converting real world objects in term of class.
  • Concept of defining an idea in term of classes or interfaces.
ex:-
public class Vehicle{
     public string model;
}


ENCAPSULATION

  • Considered as Hiding data
  • Combining methods & attributes into a class
  • Users access private attributes via public methods
ex:-

public class Person{
     private string name;

     public void setName(){

        this.name= "Lahiru";
     }

     public string getName(){

        return name;
     }

}




1 comment: