Inheritance In Java : Tutorials For Selenium WebDriver

Till straightaway nosotros conduct keep learnt many tutorials on coffee software evolution linguistic communication similar Methods,  Access Modifiers, Static as well as Non Static, Object, Constructor, and Many More Tutorials On Java... All these java software development object oriented concept tutorials are rattling much useful inward selenium webdriver software automation examine instance development. That's why I recommend you lot all to larn them rattling carefully. All these software automation testing tutorials volition too helps you lot to overstep selenium webdriver Interview. Now permit me conduct keep you lot ane stride ahead to Inheritance In java software evolution language.

What Is Inheritance In Java?
Inheritance(parent-child) Is rattling useful concept of coffee object oriented software programming linguistic communication past times which nosotros tin reuse the code of raise class. Inheritance Is providing us a machinery past times which nosotros tin inherit the properties of raise shape In to kid class. Example : Audi shape Is kid shape of Car class as well as then Audi class tin access/use all the non private properties (methods, variables..etc) of Car class. Using Inheritance, nosotros tin reuse the code of raise shape In to kid shape therefore that size of code volition decrease. Maintenance of code volition live on too rattling easy.

VIEW EXAMPLE OF USING INHERITANCE IN SELENIUM WEBDRIVER

extends keyword Is used to Inherit kid shape from raise class. Let me present you lot rattling unproblematic instance of Inheritance In java. In this example, Car shape Is raise shape of Audi shape therefore all the non somebody properties of Car shape are Inherited as well as able to operate In Audi class.

Parent Class
public shape Car {//Car Class Is Parent Class Of Audi Class         somebody String type="Vehicle";  world static int wheels = 4;  world String color = "blue";  String fuel = "Petrol";    world String getfuel(){     provide fuel;  }    protected void Seats(){   int spot = 4;   System.out.println("Car Seats = "+seat);    } }

Child Class or Sub Class
public shape Audi extends Car{//Audi Is kid Class Of Car Class.  world int speed=150;    world static void main(String[] args) {     Audi H5N1 = novel Audi();   A.printdetails();   //Can access instance variable of raise shape using object reference of kid shape Inside static methods.   System.out.println("Color Of Audi = "+A.color);   //Can access non static method of raise shape using object reference of kid shape Inside static methods.   System.out.println("Fuel Of Audi = "+A.getfuel());  }    world void printdetails(){   //Can access shape variables of raise shape straight Inside kid shape non static methods.   System.out.println("Wheels Of Audi = "+wheels);   System.out.println("Speed Of Audi = "+speed);   //Can access non static methods of raise shape straight Inside kid shape non static methods.   Seats();                 //Can non access somebody variable of raise shape In kid class.   //System.out.println("Wheels Of Audi = "+type);  } }

Output of to a higher house instance volition looks similar bellow.
Wheels Of Audi = iv Speed Of Audi = 150 Car Seats = iv Color Of Audi = bluish Fuel Of Audi = Petrol

If you lot volition written report to a higher house instance carefully, You tin sympathize It easily that In kid class, nosotros tin access exclusively non somebody members of raise class. This Is but basic instance of Inheritance In  Java.

Overriding
In sub class, When you lot exercise a method alongside same signature, provide types as well as arguments of raise class's method as well as then that sub class's method Is known equally overridden method as well as It Is called equally overriding In java. Overriding Is useful to modify to the demeanour of raise shape methods. Let me present you lot unproblematic instance of method overriding In java.

Note : Method overriding is dissimilar than method overloading. VIEW POST on method overloading.

Consider same to a higher house given example. Generally all cars conduct keep iv seats therefore nosotros conduct keep created Seats() method alongside iv spot variable. But supposing ford auto has half-dozen seats as well as I wants to impress half-dozen seats for Ford car. In this instance nosotros tin operate method overriding In Ford shape equally bellow. For this example, Consider Car shape of to a higher house instance equally raise shape of Ford class. Here method Seats() Is overridden In sub class.
public shape Ford extends Car{//Ford Is kid Class Of Car Class.   world static void main(String[] args) {   Car C = novel Ford();//Created Ford Class object alongside Car Class reference.   C.Seats();  }    //Parent shape method Seats Is overridden In kid class.  protected void Seats(){   int spot = 6;   System.out.println("Audi Seats = "+seat);    }  }

Output of to a higher house instance volition looks similar bellow.
Audi Seats = 6

Here, method of sub shape Is called at house of raise class. Another master copy affair to honour hither Is nosotros conduct keep created object of kid shape but reference Is given of raise class. You tin stance usage of "final" keyword inward THIS POST.

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM

http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post