ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
what is the difference between static block and static 
method
 Question Submitted By :: Pavani
I also faced this Question!!     Rank Answer Posted By  
 
  Re: what is the difference between static block and static method
Answer
# 1
static block will execute when ever execution starts, it 
means this block executes first of all, where as static 
block have to call seperately and also it can call with out 
object instance.
 
Is This Answer Correct ?    7 Yes 10 No
Hathwar
 
  Re: what is the difference between static block and static method
Answer
# 2
Static Block  is executed when the Program starts.

Example :

public class StaticExample {

	static{
		System.out.println("Hello");
	}
	
	public static void main(String args[]){
		
	}
}

When we run this program it will print Hello.

Static Methods are executed when those methods are called 
from another static class or method

Example :

public class StaticExample {

	static void printString(){
		System.out.println("Hello");
	}
	
	static void testStaticMethod(){
		printString();
	}
	
	public static void main(String args[]){
		testStaticMethod();
	}
}
 
Is This Answer Correct ?    22 Yes 0 No
Lolo
 
 
 
  Re: what is the difference between static block and static method
Answer
# 3
i  think  static block is  executed, when  the  class is 
loaded.That  means  at  the  time  of  compile time.so  that
 block  sill executed  first.

where as static method have to call seperately and also it
can call with out object instance.so it executed when run time.
 
Is This Answer Correct ?    12 Yes 5 No
Navaneesh
 
  Re: what is the difference between static block and static method
Answer
# 4
public static void main(string args[])
is also static method do u call this method?
 
Is This Answer Correct ?    3 Yes 2 No
Maruti
 
  Re: what is the difference between static block and static method
Answer
# 5
static block is used to initialize the variables during the 
JVM startup.
static methods are getting called with out creation of any 
instance.
 
Is This Answer Correct ?    2 Yes 1 No
Ravikiran
 
  Re: what is the difference between static block and static method
Answer
# 6
As soon as the class is loaded, the static block will be 
executed. Where as the static method should be called 
explictly.
 
Is This Answer Correct ?    7 Yes 1 No
Raghavendra
 
  Re: what is the difference between static block and static method
Answer
# 7
Static blocks execute first n than static method.It means 
static block have high priority compare to static method
 
Is This Answer Correct ?    2 Yes 4 No
Mahendra Pratap Singh
 
  Re: what is the difference between static block and static method
Answer
# 8
static block will be called at the time of loading the 
class.it can be called once.developer can not be called 
expecitly
static method will called at the time of loading the 
class.here we can call expecitly by using there classname
 
Is This Answer Correct ?    0 Yes 0 No
Khasim
 
  Re: what is the difference between static block and static method
Answer
# 9
Static block is executed when the class which contain static
block is loaded in to memory and static method is executed
when it is called. Mostly static block is used for
Initialization of static members.
 
Is This Answer Correct ?    1 Yes 0 No
Himanshu Kumar Upadhyay
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
What are virtual functions?  2
waht happens when a return type ,even void is specified for a constructor?  10
what is polymorphism? Zensar5
What is meant by event handling in SAX parser? Ness-Technologies1
Have you worked on bits programming? examples?What is bit? How many bits are there in the byte?  1
Q1.A. Write note on “The class path Environment Variable”? B. Which are different kinds of source code? Q2.A. How to create an interface? B. Why convert an applet to an application? Q3.A. How to use Media tracker Class. B. How to use string tokenizer class. Q4 A. Explain the overview of UDP messaging. B. Difference between SQL Exception class and SQL Warning class. Q5. A. How to create com object in Java? B. Write short notes on “The properties class” Q6. A. When object is created and destroyed? B. Explain the JDB in depth & command line. C. Write short notes on Web Sites. iGate2
How do u provide security in java  1
define System.out.println(); what is the meaning!  8
Name the method of a Container that can be used to cause a container to be laid out and redisplayed?  1
Can an unreachable object become reachable again?  3
What is data abstraction? Elaborate with example? BMC3
What is the ResourceBundle? Elementus-Technologies2
What are order of precedence and associativity, and how are they used?  1
what are the diffrences between interface and abstract class?  4
What is the Dictionary class?  1
what is servlet filter?  1
What is anonymous class?  2
write a progam hashmap & hashtable? IBM2
what is Assertion? Wipro2
What is the catch or declare rule for method declarations?  1
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com