Wednesday, April 15, 2015

Core Java Interview Questions

9:16 PM - By Manu 0

Hello friends In this post we would like to share most of the frequently asked java interview questions.These interview questions are sufficient to clear interview :)
These interview questions are really helpful for the people who are having  2,3 and 4+ Years exp in Java
In this FAQS we will cover all the concepts  , we tried to cover almost all the concepts in Java

Q) Explain  Oops concepts?

  Oops : Object oriented programming system
     Following are the important oops concepts
     1) Abstraction
     2) Encapsulation
     3) Ploymorphism
     4) Inheritance

Abstraction :  
Nothing but representing the essential futures without including background details.

Encapsulation:
Wrapping of data and function into a single unit called encapsulation, the single unit formed is called object.
 Ex:- all java programs.
(Or)
Nothing but restricting data, like the variables declared under private of a particular class are accessed only in that class and cannot access in any other the class. Or Hiding the information from others is called as Encapsulation.
Or
Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse.

Ploymorphism:
Ability to take more than one form, in java we achieve this using Method Overloading (compile time polymorphism),

Method overriding (runtime polymorphism)
Ex:  calculateSum(int x,int y), calculateSum(int x, int y,int z)
If observe above calculateSum() is having polymorphic nature,  two methods are having same method name but with different parameters one with two and one with three, the same method will return sum of two numbers or sum of three numbers depending upon the parameters passed

Inheritance:
Is the process by which one object acquires the properties of another object.
The advantages of inheritance are
Reusability of code and accessibility of variables and methods of the super class by subclasses(Please note this is very important point in interview).

For example refer --

Q)What is class and Object , how to create Object for a class?
Class - class is a blue print of an object
Object- instance of class.
Object Creation:
Hello h= new Hello();
In the above statement Hello is the class name , h is  reference variable for Hello class and new is the key word which is responsible for creation object for class Hello and Hello() is the constructor. 

Q) What is Constructor?
Constructor
The automatic initialization is performed through the constructor
a) Constructor has same name has class name.
b) Constructor has no return type not even void. We can pass the parameters to the constructor.
c) this()  is used to invoke a constructor of the same class.
d) Super () is used to invoke a super class constructor.
e)Constructor is called immediately after the object is created before the new operator completes.

Note: this and super are the keywords

1) Constructor can use the access modifiers public, protected, private or have no access modifier
2) Constructor can not use the modifiers abstract, static, final, native, synchronized or strictfp
3) Constructor can be overloaded, we cannot override.
4) You cannot use this () and Super() in the same constructor.

Ex programme:
Class A(
A(){
System.out.println("hi");
}}
Class B extends A {
B(){
System.out.println("India");
}}
Class print {
Public static void main (String args []){
B b = new B();
}
Output is : hi India

Q) Differences between constructors and methods
Differences between constructors and methods explained in below table
If method is having same name as class name and having void return type , then it is not a constructor, its a just method.



Q) Where Objects,Methods and Variables are created ?
Object is constructed either on a memory heap or on a stack.
Memory heap
Generally the objects are created using the new keyword. Some heap memory is allocated to this newly created object. This memory remains allocated throughout the life cycle of the object. When the object is no more referred,the memory allocated to the object is eligible to be back on the heap.
Stack
During method calls, objects are created for method arguments and method variables. These objects are created on stack.

Q) Explaing System.out.println()?
System: is the final  class of java.lang package.
Out: is an instance variable of java.lang.System class.
println(): is a methd of java.io.printWriter.Which is used to print to console.

We will discuss more about final and instance varibale in coming questions.













Share This Post

0 comments:

Feel Free to Share your Feeling about these content

© 2014 GSDUNIA. WP Theme-junkie converted by Bloggertheme9
Powered by Blogger.
back to top