{"id":1214,"date":"2021-10-23T17:24:35","date_gmt":"2021-10-23T17:24:35","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/?p=1214"},"modified":"2021-11-30T18:39:08","modified_gmt":"2021-11-30T18:39:08","slug":"sdet-interview-questions-part-1","status":"publish","type":"post","link":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2021\/10\/23\/sdet-interview-questions-part-1\/","title":{"rendered":"Sr.QA and SDET Interview Questions in Java &#8211; Part 1"},"content":{"rendered":"<h3 id=\"t-1635009289844\"><a name=\"_Toc82204558\" style=\"outline: none;\">This<\/a> is Part 1 in the series of SDET Interview questions and answers in Java<\/h3>\n<h3 id=\"t-1638297369020\"><a name=\"_Toc82204558\" style=\"outline: none;\">1. What is the difference between JDK, JRE, and JVM?<\/a><\/h3>\n<p><strong>JDK<\/strong> is Java Development Kit it is used for Developing Java Application<\/p>\n<p><strong>JRE<\/strong> is Java Runtime Environment that is used for running java programs\/application<\/p>\n<p><strong>JVM<\/strong> is Java Virtual Machine that provides a Platform Independent execution environment for running your code.<\/p>\n<h3 id=\"t-1638297369021\"><a name=\"_Toc82204559\" style=\"outline: none;\">2. What are the different types of constructors in Java? And How to overload Constructor?<\/a><\/h3>\n<p><strong>Constructor<\/strong> is a block of code, which will have a name as the Class name. The constructor will be executed when a new instance of the class is created.<\/p>\n<p><strong>There are two types of Constructor<\/strong><\/p>\n<p><em><strong>Default Constructor<\/strong><\/em><\/p>\n<p>Default constructor will not have any parameter, If you don\u2019t define it then compiles creates one automatically. Default constructor will be called by compiler if there is no other constructor.<\/p>\n<p><span style=\"text-decoration: underline;\">Example Code Snippet<\/span><span style=\"text-decoration: underline;\"><\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class Academy {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; \/\/ Constructor<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; Academy() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;Constructor called&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class SampleClass {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void main(String args[]) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;\/\/ this invokes default constructor.<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Academy academy = new Academy();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}&nbsp;&nbsp;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p><strong><span style=\"text-decoration: underline;\"><span style=\"color: rgb(255, 255, 255);\">Output:<\/span><\/span><\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">Constructor called<\/span><\/p>\n<p><strong>Parameterized Constructor<\/strong><\/p>\n<p>The parameterized constructor will have parameters, this is mainly used for initialization purposes. You can pass different values to a parameterized constructor at the time of object creation, but values should match the constructor signature<\/p>\n<p><span style=\"text-decoration: underline;\">Example Code Snippet<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp; &nbsp; class Academy {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; int a=0;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; int b=0;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; \/\/ Parameterized Constructor<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; Academy(int a, int b) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;Constructor called&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;Addition of &#8220;+a+&#8221; and &#8220;+b+&#8221; = &#8220;+(a+b));<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class SampleClass {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static void main(String args[]) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ this invokes default constructor.<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Academy academy = new Academy(10,20);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\"><strong><span style=\"text-decoration: underline;\">Output:<\/span><\/strong><\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">Constructor called<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">Addition of 10 and 20 = 30<\/span><\/p>\n<h3 id=\"t-1635009289846\"><a name=\"_Toc82204560\" style=\"outline: none;\">3. What is the static keyword? How it can be used?<\/a><\/h3>\n<p>The static indicates that the particular member belongs to a type itself, rather than to an instance of that type. That means a static member of the class can be accessed before creating any object for that class.<\/p>\n<p>Static keywords can be used for<\/p>\n<ul>\n<li>Variable, also called static fields or Class Variables<\/li>\n<li>Method<\/li>\n<li>Block<\/li>\n<li>Nested Class<\/li>\n<\/ul>\n<p><strong>Static Variable or Static Fields:<\/strong><\/p>\n<p>When you prefix fields or variables with static which is called a static variable. When you create the static variable single copy of that variable is created and shared among all instances of an object.<\/p>\n<ul>\n<li>The static variable associated with the class can be accessed directly using the class name. The object reference is not needed.<\/li>\n<li>Static variables are created at the class level.<\/li>\n<\/ul>\n<p><strong>Example Code Snippet<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class SampleClass{<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; \/\/Example of static variable<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static int exampleVariable =10;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><strong>Static method<\/strong><\/p>\n<p>When you create a method and prefix with a static keyword it becomes static methods, static methods belong to the class, not to any object.<\/p>\n<ul>\n<li>The static method can be accessed using class name no need for any object reference. The main method is the example of a static method which is commonly used<\/li>\n<li>A static method cannot be overridden<\/li>\n<li>You cannot create abstract method using static keyword<\/li>\n<li>this or super keyword cannot be used for static methods<\/li>\n<\/ul>\n<p><strong>Example Code Snippet<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class SampleClass{<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void sampleMethod(String name) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(name);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><strong>Static Block<\/strong><\/p>\n<p>A block of code which is used with static keyword is known as static block. Static block is mainly used for initializing static variables. You can have multiple static block inside single class. Static block will be executed before main method<\/p>\n<p><strong>Example Code Snippet<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class SampleClass{<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static List&lt;String&gt; fruits = new LinkedList&lt;&gt;();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; static {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fruits.add(&#8220;Apple&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fruits.add(&#8220;Banana&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fruits.add(&#8220;Kiwi&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void main(String args[]) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(SampleClass.fruits.get(0));<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><strong><span style=\"color: rgb(255, 255, 255);\">Output: Apple<\/span><\/strong><\/p>\n<p><strong>Static Class<\/strong><\/p>\n<p>When you create a class inside another class it is called a nested class, static class only be created as a nested class. Members of the static class can be directly accessed using the outer class.<\/p>\n<ul>\n<li>A static class cannot access non-static members of the Outer class<\/li>\n<li>Static class members can be called with outer class reference<\/li>\n<li>Static classes are always nested or inner class<\/li>\n<li>You can use access modifier for static class<\/li>\n<\/ul>\n<p><strong>Example Code Snippet<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class SampleClass{<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; \/\/static class declared here<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; static class SampleStaticClass{<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int a = 10;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void main(String args[]) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SampleClass.SampleStaticClass staticClass = new SampleClass.SampleStaticClass();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(staticClass.a);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<h3 id=\"t-1635009289847\"><a name=\"_Toc82204561\" style=\"outline: none;\">4. What is this final keyword? how I can be used?<\/a><\/h3>\n<p>The final keyword is used for restricting the behavior variable, method, class, etc.<\/p>\n<p>The final keyword can be used with<\/p>\n<ul>\n<li>Variable<\/li>\n<li>Methods<\/li>\n<li>Class<\/li>\n<\/ul>\n<p><strong>Final Variable:<\/strong><\/p>\n<ul>\n<li>If you prefix any variable with a final keyword then it is called the final variable.<\/li>\n<li>Once the value is assigned to the final variable you cannot change it.<\/li>\n<li>If you don\u2019t initialize the final variable during declaration it is called blank final variable, it can be initialized through constructor.<\/li>\n<li>A&nbsp; final variable can be declared as a static<\/li>\n<li>You can assign the final static variable during the declaration<\/li>\n<li>If you have created a blank static final variable, it can be initialized inside the static block.<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline;\">Example Code Snippet<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class FinalTest{<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void main(String args[]) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; final int i = 10;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><strong>Final Methods<\/strong><\/p>\n<p>If you prefix the final keyword to methods it becomes the final method<\/p>\n<p>Final methods cannot be overridden<\/p>\n<p>Static final method is completely valid in java, and it can be declared<\/p>\n<p><strong>Example Code Snippet<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">final void print() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; int a = 10;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; System.out.println(a);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><strong>Final Class<\/strong><\/p>\n<p>If you prefix final to class, then it becomes the final class<\/p>\n<p>Final classes cannot be extended or inherited<\/p>\n<p>You can create the inner class as a static final<\/p>\n<p><strong>Example Code Snippet<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public final class<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">{<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp; \/\/Some Code<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<h3 id=\"t-1638297369022\"><a name=\"_Toc82204562\" style=\"outline: none;\">5. What is the difference between method overloading and method overriding?<\/a><\/h3>\n<p>Method overloading is class has more than one method of the same name but having different parameter. Method overriding Subclass provides the implementation of the method that has been declared by the Parent class is called method overriding.<\/p>\n<p>Method overloading is an example of compile-time polymorphism. Method overriding is an example of run time polymorphism.<\/p>\n<p>You cannot achieve overloading only by changing the return type. Method overriding will have usually the same return type.<\/p>\n<p>Method overloading can be achieved without inheritance. Method overriding requires inheritance<\/p>\n<p><strong>Example Code Snippet for method overloading<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">\/\/Method overloading<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class SampleClass{<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public void add(int a, int b, int c) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/some code<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public void add(int a, int b) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/some code<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><strong>Example Code Snippet for Method overriding<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">\/\/Method overriding<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class SampleClass{<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public void someMethod() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;Super Class&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class MyClass extends SampleClass{<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public void someMethod() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;Sub Class&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<h3 id=\"t-1638297369023\">6. Could you explain IS-A and HAS-A relationship?<\/h3>\n<p><strong>IS -A relationship<\/strong><\/p>\n<p><strong>IS-A relationship<\/strong> is formed in inheritance, The class which inherit is known as subclass or child class. That means that child class is the type of parent class.<\/p>\n<p>For example, Orange is a Fruit, you need to extend fruit class to make IS-A relationship<strong>&nbsp; <\/strong><\/p>\n<p><strong>Example Code Snippet&nbsp; : IS-A Relationship<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class Fruit{<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; \/\/some code<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">\/\/IS-A relationship<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class Orange extends Fruit {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">\/\/some code<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><strong>HAS -A relationship<\/strong><\/p>\n<p><strong>HAS-A relationship<\/strong> is composition, which means you are creating the object of a class inside another class. Let\u2019s take the example of Room. The room has a chair. The room should contain chair class reference, i.e you need to create an instance of Chair particular class inside the Room class.<\/p>\n<p><strong>Example Code Snippet : HAS-A Relationship<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class Room {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; Chair chair = new Chair();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<h3 id=\"t-1638297369024\"><a name=\"_Toc82204564\" style=\"outline: none;\">7. Explain this and super keyword<\/a><\/h3>\n<p><strong>this<\/strong> keyword is used to refer current class instance\/object<\/p>\n<p><strong>this keyword<\/strong> can be used to<\/p>\n<ul>\n<li>Current class instance variable<\/li>\n<li>Invoke current class methods<\/li>\n<li>Invoke current class constructor<\/li>\n<li>Can be used to pass the argument to a method<\/li>\n<li>Can be used to pass the argument to a constructor<\/li>\n<li>Return the current class instance<\/li>\n<\/ul>\n<p><strong>Super Keyword<\/strong><\/p>\n<ul>\n<li>The super keyword is a reference variable that is used to refer to parent class objects<\/li>\n<li>super can be used to refer to immediate parent class instance variable<\/li>\n<li>super can be used to invoke the parent class method<\/li>\n<li>super can be used to invoke parent class Constructor<\/li>\n<\/ul>\n<p><strong>Example Code Snippet : this and super keywords<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class First {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; void print() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;Printing First&#8230;&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class Second extends First {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; void printOneMore() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;Printing Second&#8230;&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; void myMethod() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; super.print();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.printOneMore();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class KeywordTest {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void main(String args[]) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Second d = new Second();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d.myMethod();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<h3 id=\"t-1638297369025\"><a name=\"_Toc82204565\" style=\"outline: none;\">8. How to check instance of Specified type? Explain with example<\/a><\/h3>\n<p>The Java provides <strong>instanceof<\/strong> operater which can be used to check instance of Specified type.<\/p>\n<ul>\n<li>The <strong>instanceof<\/strong> operator returns either true or false<\/li>\n<li>The <strong>instanceof<\/strong> operators are used for down casting<\/li>\n<li>The <strong>instanceof<\/strong> operator works on the principle of the is-a relationship<\/li>\n<li>If you <strong>instanceof<\/strong> Operator for null object it will return false.<\/li>\n<\/ul>\n<p><strong>Example Code Snippet<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class Apple {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void main(String args[]) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Apple apl = new Apple();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (apl instanceof Apple) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; System.out.println(&#8220;apl is instance of Apple&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;apl is not an instance of Apple&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<h3 id=\"t-1638297369026\"><a name=\"_Toc82204566\" style=\"outline: none;\">9. What is a package in Java? What are different types of packages? Can we create a custom package?<\/a><\/h3>\n<ul>\n<li>A package is a group of similar interfaces, classes, and subclasses<\/li>\n<li>Custom package can be created with the package keyword<\/li>\n<li>Access modified can be used for packages<\/li>\n<li>Import keyword is used for importing already created packages.<\/li>\n<li>The package is a good example of java encapsulation<\/li>\n<li>Packages that are inside another package are the sub-packages<\/li>\n<li>Java provides many built-in packages and it allows you to create custom ones as well<\/li>\n<\/ul>\n<p><strong>Some of the built-in packages are<\/strong><\/p>\n<p><strong>java.lang : <\/strong>This package contains the classes and interfaces that are fundamental to the core Java<\/p>\n<p><strong>java.util<\/strong> : This library provides users with generic java utilities like collections framework, formatted printing and scanning, array manipulation utilities, event model, date and time facilities, internationalization, and miscellaneous utility classes<\/p>\n<p><strong>java.io<\/strong> This library is very useful and contains the classes that handle fundamental input and output operations in Java<\/p>\n<p><strong>java.net<\/strong> : This package contains classes and interfaces that provide a powerful infrastructure for networking in Java.<\/p>\n<p><strong>java.sql :<\/strong> This package contains all the SQL-related classes and interfaces. This package provides the API for accessing and processing data stored in a data source.<\/p>\n<p><strong>We can create custom packages in Java<\/strong><\/p>\n<p><strong>Example Code Snippet<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">package packageName; \/\/ Use package keyword for creation<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class ExampleClass{&nbsp;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;\/\/ Some Code Here<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">} <\/span><\/p>\n<h3 id=\"t-1638297369027\"><a name=\"_Toc82204567\" style=\"outline: none;\">10. What is run time polymorphism in Java?<\/a><\/h3>\n<p>Runtime polymorphism or Dynamic Method Dispatch is a process in which a call to an overridden method is resolved at runtime rather than compile-time.<\/p>\n<ul>\n<li>The overridden method is called through the reference variable of a superclass<\/li>\n<li>The object is determined by the object being referred to by the reference variable<\/li>\n<li>The reference variable of Parent class refers to the object of Child class is called upcasting<\/li>\n<\/ul>\n<p><span style=\"color: rgb(255, 255, 255);\">class Car {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; void print() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;Inside Car Class&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class Honda extends Car {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; void print() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;Inside Honda Class&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class MainClass {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void main(String args[]) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Car car = new Honda();\/\/ This is Upcasting<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; car.print();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<h3 id=\"t-1638297369028\"><a name=\"_Toc82204568\" style=\"outline: none;\">11. What is the difference between static and dynamic binding in java?<\/a><\/h3>\n<ul>\n<li>The binding which can be resolved by the compile-time is static binding. The binding which will be resolved at the run time is known as dynamic binding.<\/li>\n<li>Type information is used for resolving static binding. Object information is used for resolving dynamic binding<\/li>\n<li>Method overloading is an example of static binding. Method overriding is an example of dynamic binding<\/li>\n<li>Static binding is also known as early binding. Dynamic binding is also known as late binding<\/li>\n<\/ul>\n<p><strong>Example Code Snippet: Static Binding <\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">\/\/Static binding<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class MainClass {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; void print() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;Printing&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void main(String args[]) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MainClass mc = new MainClass();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mc.print();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><strong>Example Code Snippet: Dynamic binding <\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">\/\/Dynamic Binding<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class Fruit {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; void print() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;This is fruit class&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class Apple extends Fruit {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; void print() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;This is Apple&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void main(String args[]) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fruit f = new Apple();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f.print();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p style=\"text-align: center;\"><strong><em><span style=\"text-decoration: underline;\">Course Alert<\/span><\/em><\/strong><strong>If you are interested in landing a SDET or Sr. QA Automation Engineer role, check out our popular SDET course to learn the fundamental skills required an SDET needs to perform at work. Also, I have another popular course which covers Top 150+ Interview questions most commonly asked in SDET \/ Automation interviews.<\/strong><\/p>\n<ul>\n<li><span><a href=\"https:\/\/courses.rahulshettyacademy.com\/p\/sdet-test-architect-essentials-road-to-full-stack-qa\" target=\"_blank\" style=\"outline: none;\" rel=\"noopener noreferrer\">SDET\/Test Architect Essentials -Road to Full stack QA<\/a><\/span><\/li>\n<li><span><a href=\"https:\/\/courses.rahulshettyacademy.com\/p\/sdet-qa-automation-interview-kit-java-logic-programs\" target=\"_blank\" style=\"outline: none;\" rel=\"noopener noreferrer\">SDET\/QA Automation Interview Kit + Java logic Programs<\/a><\/span><\/li>\n<\/ul>\n<h4><em><strong>A Quick Note<\/strong><\/em><\/h4>\n<p>Please remember all these courses comes with <strong>100% Lifetime acces<\/strong><strong>s<\/strong> and <strong>free updates for Lifetime!!<\/strong><\/p>\n<p>Please click on the link <strong><span style=\"text-decoration: underline;\"><em><a href=\"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2021\/10\/23\/sdet-interview-questions-part-2\/\" target=\"_blank\" style=\"outline: none;\" rel=\"noopener noreferrer\">Sr.QA and SDET Interview Questions in Java \u2013 Part 2<\/a><\/em><\/span><\/strong> to continue to part-2 series of this article.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is Part 1 in the series of SDET Interview questions and answers in Java 1. What is the difference between JDK, JRE, and JVM? JDK is Java Development Kit it is used for Developing Java Application JRE is Java Runtime Environment that is used for running java programs\/application JVM is Java Virtual Machine that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1215,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-1214","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-interview-questions","post-wrapper","thrv_wrapper"],"_links":{"self":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1214"}],"version-history":[{"count":14,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1214\/revisions"}],"predecessor-version":[{"id":1359,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1214\/revisions\/1359"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/1215"}],"wp:attachment":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}