Java Questions and Answers

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Assignment

1) Explain OOPs concept ? And where have you used all 4 of them in your framework.
Answer: OOP : Object Oriented Programming : It is to design a program using classes and
objects.
Object : Object has state and behavior. State has some Identification. Behavior means some
action of that state.
Example : A dog is an object because it has states like color, name, breed, etc. as well as
behaviors like wagging the tail, barking, eating, etc.Object is actually derived something from
class.
Class : it is the blueprint on the basis of which the object is created. Object is inheriting the
properties of class. Object is created from class.
Example : JsonPath Jsp = new JsonPath();
Jsonpath() : Class
Jsp : Object
Here , all the method in JsonPath() class are come in Jsp Object
Where have you used all 4 of them in your framework.
 Inheritance The mechanism in Java by which one class acquires the properties
(instance variables) and functionalities of another class is known as Inheritance.
 Polymorphism Polymorphism allows us to perform a task in multiple ways.

 Encapsulation All the classes in a framework are an example of Encapsulation.


 Abstraction Abstraction is the methodology of hiding the implementation of internal
details and showing the functionality to the users.

2) Explain the difference between JVM, JDK and JRE


Answer:
JRE : JRE stands for “Java Runtime Environment”. It comprises of the JVM (Java Virtual
Machine), Java platform classes, and supporting libraries.
Using JRE, we can only execute already developed applications. We cannot develop new
applications or modify existing applications.
JRE only provides Runtime Environment.
JDK : JDK stands for Java Development Kit. It is a superset of JRE (Java Runtime
Environment).
Using JDK, we can develop, compile and execute (run) new applications and also we can
modify existing applications. JDK includes JRE and development tools (environment to
develop, debug and monitor Java programs).
JVM : JVM stands for Java Virtual Machine. JVM drives the java code. Using JVM, we can
run java byte code by converting them into current OS machine language. It makes Java to
become a portable language (write once, run anywhere)
What is JIT Code : The JIT compiler helps improve the performance of Java programs by
compiling bytecodes into native machine code at run time.
3) Explain multiple , single and multi-level inheritance.
Answer: Single Inheritance : One Parent class is directly inherited by child class
Multi-level Inheritance : One Parent class is inherited by child class another inherited another
child class.
Multiple Inheritance : Two Parent class and one child class.

4) Types of polymorphism?
Answer: Polymorphism allows us to perform a task in multiple ways. the word Polymorphism
‘Poly’ means ‘Many’ and ‘Morphos’ means ‘Shapes’.
Types of Polymorphism
 Method Overloading
 Method Overriding
5) Method overloading and how to implement it ?
Answer: In one class two method name are same name are known as “Method Overloading”.
Why need of Method overloading – when we have two different arguments.
When we want different output from same method (Input).
For eg. public class Soap
{
Public static void display (){}
Public static void display (int a){} // pass argument
}
Need for overloading: Function is same but depending on argument your output result is
change. This is used when different result from argument.
6) Method overriding and how to implement it ?
Answer: Method Overriding
 When we want to enhance or change the functionality of inherited object to achieve
desired results.
 To implement this method definition should be same.
 Using overriding we can only enhance the properties of class. We cannot reduce
properties.
7) What points should be taken care of while overriding a method .
Answer:
 To implement this method definition should be same.
 Method definition= method name, argument, return type.

8) Use of final keyword.


Answer: Using final keyword we prevent Inheritance and Overriding(type of Polymorphism).

9) Explain different access modifiers supported by JAVA.


Answer: Access modifiers are keywords used to control the visibility of fields, methods, and
constructors in a class.
Four Types of Access Modifiers
Private: We can access the private modifier only within the same class and not from outside
the class.
Default: We can access the default modifier only within the same package and not from
outside the package.
Protected: We can access the protected modifier within the same package and also from
outside the package with the help of the child class.
Public: We can access the public modifier from anywhere. We can access public modifiers
from within the class as well as from outside the class and also within the package and outside
the package.
10) What is JRE System library ?
Answer: JRE System Library implements the Java API in Eclipse IDE. So all the predefined
functions of Java, can be accessed by the Java Programs written in Eclipse IDE because of this
JRE System Library.
11) What is external Library , how to add them and name some external libraries you have used
in your framework.
Answer: External library are imported from outside so that we can perform specific job.
From maven repository we can download them. It is added as dependencies outside the built
in porm.xml file. That are testNg, RestAssured, ApachePIO.

You might also like