Java Interview Questions
INTERVIEW QUESTIONS ON OOPS
1. What are the features of OOPs?
Ans:- The different features of OOPs are:
1. Class
2. Abstraction
4. Polymorphism
5. Inheritance
2. What is Polymorphism?
Ans:- Polymorphism is a feature of OOP where an object can have multiple forms
3. What is Inheritance?
Ans:- Inheritance is a feature of OOP where a child class inherits features of a parent class.
4. What is Multiple Inheritance and does Java support it?
Ans:- Multiple Inheritance is a type of Inheritance where a single child class inherits features of multiple parent classes. It is not supported by JAVA because there is a problem with multiple inheritance and that is if multiple parent classes have same method name then it will be difficult for the compiler to understand which method to be called.
5. What is Association, Aggregation, Composition?
Ans:- Association defines relationship between 2 classes. For example a Vehicle class and Car class are interrelated.
Aggregation is a type of Association which defines weak relationship. For example Bike class and Indicator class are interrelated but weakly. It is because a bike can work perfectly without an indicator. Another example is Wallet and Money. Money can go without Wallet and vice versa.
Aggregation is a type of Association which defines weak relationship. For example Bike class and Indicator class are interrelated but weakly. It is because a bike can work perfectly without an indicator. Another example is Wallet and Money. Money can go without Wallet and vice versa.
Composition is another form of Association which defines strong relationship. For example Bike class and Engine class. Bike cant run without an Engine. Another example is Human and Heart.
6. What is the difference between OOP and Object Based Programming?
Ans:- The basic difference is Object Based Programming have no concept of Inheritance. Example is JavaScript, Vb Script.
INTERVIEW QUESTIONS ON FREQUENTLY USED TERMS
1. What is the difference between JDK, JRE, JVM?
Ans:- JDK is Java Development Kit. It provides the environment to develop and run programs. JRE is Java Run time Environment which provides runtime environment only. Both JDK and JRE physically exist. JVM is Java Virtual Machine which does not physically exist. It is a system software to compile and interpret Java code.
2. What is class-loader?
Ans:- Classloader loads classes and interface into the memory. Example:- Bootstrap loader.
INTERVIEW QUESTIONS ON VARIABLES IN JAVA
1. What is a static variable?
Ans:- A variable declared outside the function as static is called static variable. Object is not needed to use this variable. The memory is allocated only once at the time of execution.
2. Can a local variable be declared static?
Ans:- No
3. Guess the output of the following code:-
class Main
{
public static void main(String args[])
{
int t;
System.out.println(t);
}
}
Ans:- Compile time error. Unlike class variables, local variables need to be initialized with a value.
INTERVIEW QUESTIONS ON DATA TYPES IN JAVA
1. What is the range of byte data type?
Ans:- Byte data type ranges from -128 to 127
byte data type can store 8 bit data. 2^8 (2 to the power 8) = 256. To store both negative and positive values, its range is -128 to 127
2. What is the range of short data type?
Ans:- Short data type ranges from -32768 to 32767
short data type can store 16 bit data. 2^16 (2 to the power 16) = 65536. To store both negative and positive values, its range is -32768 to 32767
3. What is the range of char data type?
Ans:- Char data type ranges from 0 to 65536
char data type can store 16 bit data. 2^16 (2 to the power 16) = 65536. Char stores only positive values thus, its range is 0 to 65536
4. What coding technique does char use?
Ans:- UNICODE
JAVA INTERVIEW QUESTIONS ON MAIN FUNCTION
1. What if I write static public void instead of public static void?
Ans:- The program will run perfectly.
2. What if we remove static from main function's signature?
Ans:- The program will compile and execute but JVM will have to create an object and allocate extra memory to execute main function. Thus there is wastage of memory.
3. What is static block?
Ans:- static block is a block declared as static to declare static variables and methods. It executes before the execution of main function.
4. Can a program execute without any function?
Ans:- Yes, using Static block.
class Main
{
static{
System.out.println("this is a static block");
}
}
Comments
Post a Comment