Java Questions For Selenium Interview

Part 8

36 : What is the difference betwixt the Constructor too Method?
Answer : Main deviation betwixt the Constructor too Method is equally bellow.

Constructor :
  1. Name of the constructor must hold upwards same equally shape name.
  2. Constructor must non accept whatever furnish type.
  3. It is used to initialize the Earth of an object.
  4. It is non possible to telephone telephone constructor directly. Constructors called implicitly when the novel keyword creates an object.
Method :
  1. Method cite tin hold upwards any.
  2. Method must accept furnish type.
  3. It is used to discover demeanor of an object.
  4. Methods tin hold upwards called directly.
Read to a greater extent than on Constructor too Method.

37 : What are the dissimilar types of types of constructors inwards java?
Answer : Mainly at that spot are ii types of constructors available inwards java.
  • Default Constructor : Constructor without parameter is called default constructor.
package JAVAExamples;  world shape City {  //Default Constructor  City()  {   System.out.println("City is created");  }    world static void main(String args[]){     City c=new City();    }   }
  • Parameterized constructor : Constructor alongside parameter is called Parameterized constructor.
package JAVAExamples;  world shape City {  int id;  String name;   // parameterized Constructor  City(int i, String n) {   id = i;   cite = n;  }   void display() {   System.out.println(id + " " + name);  }   world static void main(String args[]) {   City c1 = novel City(1, "New York");   City c2 = novel City(2, "London");   c1.display();   c2.display();  } }
Output :
1 New York
2 London

38 : Write a plan for Fibonacci serial inwards Java ?
Answer : Program for Fibonacci serial is equally bellow.

package JAVAExamples;  world shape FibonacciSeries {  world static void main(String args[]) {   int x1 = 0, x2 = 1, x3, i, cnt = 15;   // To impress 0 too 1   System.out.print(x1 + " " + x2);    // loop starts from 2 equally 0 too 1 are already printed.   for (i = 2; i < cnt; ++i) {    x3 = x1 + x2;    System.out.print(" " + x3);    x1 = x2;    x2 = x3;   }  } }

39 : Write a plan to impress below given pattern.

1  1 2  1 2 iii  1 2 iii four  1 2 iii four 5

Answer : Program to impress to a higher house designing is equally bellow.

package JAVAExamples;  world shape Pattern {   world static void main(String[] args) {   for (int a = 1; a <= 5; a++) {    for (int x = 1; x <= a; x++) {     System.out.print(x+" ");    }    // To impress novel line.    System.out.println();   }  } }

40. What is the deviation betwixt “this” too “super” keywords inwards Java?
Answer : Difference is equally bellow.
  1. “this” keyword is used to shop electrical current object reference while “super” keyword is used to store super shape object inwards sub class..
  2. “this” is used to access methods of the electrical current class while “super” is used to access methods of the base of operations class.
  3. this() used to telephone telephone constructors inwards the same shape whereas super() is used to telephone telephone super shape constructor.
Read more on “super” keyword.

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