Wednesday, December 12, 2012

Differenc Between Static and Instance Variables

In case of the Instance Variable new operator creates separate memory for each and every Object.
In case of the Static Variables new operator shares the same memory for any number of objects.

The following example shows difference between Instance and Static variable.

class StaticEx 
{
StaticEx()
{
static_var++;
instant_var++;
}
public static int static_var=10;
public int instant_var=20;
public void display()
{
System.out.println("static_var value = "+static_var);
System.out.println("instant_var value = "+instant_var);
}
}
class StaticExMain
{
public static void main(String args[])
{
StaticEx   staticExObj1 = new StaticEx();
                staticExObj1.display();
StaticEx   staticExObj2 = new StaticEx();
staticExObj2.display();
StaticEx   staticExObj3 = new StaticEx();
staticExObj3.display();
}
}

OUTPUT:
static_var value = 11
instant_var value = 21

static_var value = 12
instant_var value = 21

static_var value = 13
instant_var value = 21





Core Java interview questions

The Following are the main Core Java Questions.

1.  What is a class and objects explain with example?

2.  What is a method?
3.  How to access methods in class?
4.  Difference between instance variables and static variables?
5.  What is inheritance? Different types of inheritance?
6.  What is polymorphism?
7.  Method overloading and overriding?
8.  Explain about Different types of Access Specifiers?
9.  Difference between Abstract class and interface?
10. What is Exception?
11. Different types of Exception handling?
12. What is checked and unchecked exceptions?
13. How you can handle Exceptions?
14. What is collection framework?
15. Different types of Collections?
16. what is List?
17. What is Set?
18. What is Map?
19. Difference between List, Set and Map?
20. Explain about Threads?
21. What is wrapper classes?