Java Oops Concepts

 

Inheritance : use parent class veriable and method using child class object

  1. Create object of child class and reference of child class, using this object access all methods of base class and child class

2. Create object of base class and reference of base class, allow to access all method of base class only

3. Create reference of base class but object of child class, allow to access method of base class only not child class method

Inheritance – http://www.software-testing-tutorials-automation.com/2014/04/inheritance-in-java-tutorials-for.html

Interface implement in selenium – http://www.ufthelp.com/2015/01/Java-Interface-example-in-Selenium.html

Polymorphism

2 Type of Polymorphism

  1. Compile time called early binding

Overloading : Same method name but different signature(No of arguments, Type of arg,order of arg)

e.x. add(int a, int b) and add(int a, int b, int c)

2. Runtime called Late biding

OverRidding

Abstraction

Showing the functionality by hiding the implemetation details.

Abstact class must have atleast one abstract method

Abstract class have both concreate and abstract method

In Abstract class you can define member variables

common functionality define in the abstract class and functionalty change in subclass define in asbstract method

when extend abstract class then going to implement in sub class to achive the code resuability

example:

abstract class Bank 
{
   public void diposite() {
         system.out.println("common deposite method across all banks");
    }
    public void withdraw() {
        system.out.println("common withdraw method across all bank");
     }

public abstract int calculteInterest();
}

every bank have different formula to calculating the interest so extands bank class will implement the calculateInterest method()

class HDFC extends Bank{
  @override
  public int calcualteInterst(){
      System.out.println("HDFC bank Calculate Interest Implentation");
  }
}
Bank hdfc = new HDFC();
hdfc.diposite();
hdfc.withdraw();
hdfc.calcualteInterst();

Interface

In Interface all methods are bydefault abstract

public interface BankInterface {
   public abstract  void diposite();
   public abstract void withdraw();
   public abstract void calculateInterest();
}

bydefault declare method is public even define or not.

Class impements the interface must have to define the method

class HDFC implements BankInterface{
 @override
  public void depostie(){
     System.out.println("HDFCBank deposite Implementation");
  }
  @override
  public void withdraw() {
      System.out.println("HDFCBank withdraw implentation");
  }
  @override
  public void calculateInterest(){
      System.out.println("HDFCBank calculate interest implementation");
  }
}
Bankinterface hdfcbank = new HDFCBank();
hdfcbank.deposite();
hdfcbank.withdraw();
hdfcbank.calculateInterest();

By using the interface achive multiple inheritance

Advertisements

About samp79

Professional Automation Tester
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s