Monday, April 13, 2020

About main() method in java

public static void main(String args[]){
}

Why 

  1. public  ----- so that jvm can get control of main method from anywhere
  2. static ---- so that main method could be accessed without any object reference
  3. void .... main method does not return value
  4. String args[]  ---- when you are executing jar file with java class with main method in it. we can pass String arguments to main method if needed.

Sunday, April 12, 2020

return object

Do you know we can return object in Java, for example, if you want to use WebDriver object created in a method  in someother method in someother class, you can return that object.
Syntax:

Public  Classname  methodname(){
Classname obj= new Classname();
return  obj;
}

The above example tells us how to create method to return an object.  Below is live example of WebDriver object:

Public  WebDriver  methodname(){
WebDriver  object=  new  ChromeDriver();
return  object;
}

When you call above method  in other class  like:
WebDriver object1=  methodname();

object1.url("https://www.google.com");


It will still trigger google website.