Interface In Java : Tutorials For Selenium Webdriver

I described near Inheritance together with method overriding inwards coffee software evolution linguistic communication In my previous post so I am suggesting you lot to read that post, Specially method overriding concept earlier learning near Interface In Java software development. If you lot volition become for selenium webdriver Interview together with then Interviewer volition inquire you lot starting fourth dimension enquiry : What Is WebDriver? Peoples will plow over unlike different answers but correct reply Is WebDriver Is an Interface. So It Is most Important affair for all selenium webdriver software testing tool learner to understand an Interface properly.

What Is An Interface And Why To Use It?
Using Interface, We tin exercise a contract or nosotros tin say gear upwards of rules for behaviour of software application. Interface Is looks similar shape but It Is non class. When you lot implements that Interface In whatever shape together with then all those Interface rules must travel applied on that class. In sort, If you lot Implement an Interface on shape together with then you lot must accept to override all the methods of Interface In your class. Interface volition exercise Rules To Follow construction for shape where It Is Implemented. This way, If you lot await at the code of Interface, You tin acquire Idea near your programme trouble organization logic. When you lot are designing big architecture software applications similar selenium webdriver, You tin purpose Interface to define trouble organization logic at Initial level.

Interface tin travel Implemented amongst whatever shape using implements keyword. There are gear upwards of rules to travel followed for creating an Interface. Let me tell you lot all these rules starting fourth dimension together with and then plow over you lot an instance of an Interface.
  • Interface tin non tally constructor.
  • Interface tin non tally instance fields/variables.
  • Interface tin non tally static methods.
  • You tin non instantiate/create object of an Interface.
  • Variables Inside Interface must travel static together with mandatory to initialize the variable.
  • Any shape tin Implement Interface but tin non extend Interface.
  • Can write trunk less methods Inside Interface.
  • By default all the methods together with variables of Interface are world thus no demand to furnish access modifiers.
How To Add Interface In Your Project
To add together Interface In your project, Right click on bundle together with become to -> New -> Interface. It volition opened upwards New coffee Interface popup. Give whatever advert to Interface(Example : College) together with click on salve button. It volition add together College.java Interface file nether your package.



Now allow us await at uncomplicated instance of Interface.

  • Create One Interface file amongst advert = College.java every bit shown In bellow example.
  • Create iii shape file amongst advert = Computer.java, Mechanical.java and TestCollege.java as shown In bellow example.
College.java
public interface College {//Interface file  //Initialized static variable.   //No demand to write static because It Is yesteryear default static.  String Collegename = "XYZ";    //Created non static methods without body.  void StudentDetails();  void StudentResult(); }

Computer.java
//Class file Implemented amongst Interface file using implements keyword. world shape Computer implements College {          //@Override notation describes that methods are overridden on interface method.  //Methods name, render type are same every bit methods of an Interface.  @Override  world void StudentDetails() {   System.out.println("Computer Dept. Student Detail Part");  }   @Override  world void StudentResult() {   System.out.println("Computer Dept. Student Result Part");    } }

Mechanical.java
//Class file Implemented amongst Interface file using implements keyword. world shape Mechanical implements College{   @Override  world void StudentDetails() {   System.out.println("Mechanical Dept. Student Detail Part");     }   @Override  world void StudentResult() {   System.out.println("Mechanical Dept. Student Result Part");    }  }

TestCollege.java
public shape TestCollege {//Class file. No demand to implement Interface.   world static void main(String[] args) {                 //Can access Interface variable straight using Interface name.   System.out.println(College.Collegename+" Collage pupil details.");      //Created Computer shape object amongst reference of interface College.   College compdept = novel Computer();   //Methods volition travel called from Computer class.   compdept.StudentDetails();   compdept.StudentResult();      //Created Mechanical shape object amongst reference of interface College.   College mecdept = novel Mechanical();   //Methods volition travel called from Mechanical class.   mecdept.StudentDetails();   mecdept.StudentResult();      } }

Now If you lot volition run TestCollege.java file, Output volition looks similar bellow.

XYZ Collage pupil details. Computer Dept. Student Detail Part Computer Dept. Student Result Part Mechanical Dept. Student Detail Part Mechanical Dept. Student Result Part

Selenium WebDriver And Interface
Simple instance of Interface In selenium WebDriver Is WebDriver Interface. When you lot are Initializing whatever browser using selenium WebDriver, You are writing statements similar bellow.

WebDriver driver = novel FirefoxDriver();
Or
WebDriver driver = novel ChromeDriver();
 
You tin thought to a greater extent than examples of selenium WebDriver on THIS PAGE.
Here, WebDriver Is Interface together with FirefoxDriver together with ChromeDriver are the shape files where WebDriver Interface Is Implemented.

Have you lot read article on generally asked selenium amongst coffee interview questions near abstract shape on THIS PAGE together with deviation betwixt interface together with abstract shape on THIS PAGE?
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