Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


jsreddy
java
4 Answer(s)      6 years ago
Posted in : Java Interview Questions



Advertisement
View Answers

November 1, 2008 at 9:58 AM


Hi friend,

We have

* public: The method can be accessed outside the class / package
* static: You need not have an instance of the class to access the method
* void: Your application need not return a value, as the JVM launcher would return the value when it exits
* main(): This is the entry point for the application

If the main() was not static, you would require an instance of the class in order to execute the method.
If this is the case, what would create the instance of the class? What if your class did not have a public constructor?


For more information on java visit to :

http://www.roseindia.net/java/

http://www.roseindia.net/java/beginners/staticvariable.shtml

Thanks


November 1, 2008 at 10:04 AM


Hi friend,

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.


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();
}
}

static block is used to initialize the variables during the
JVM startup.
static methods are getting called with out creation of any
instance.

A STATIC block is automatically executed the first time the class where it is defined is called.
A Static Method is excuted only when a static call is made to this method.

For more information on Java visit to :

http://www.roseindia.net/java/beginners/
http://www.roseindia.net/java/beginners/staticvariable.shtml
http://www.roseindia.net/java/beginners/howtoaccessstaticmethod.shtml

Thanks


November 1, 2008 at 1:40 PM


You can not do that because main method should be directly available to JVM., Its not a method is a thread. So for that we need context of the class. So we r giving instruct to jvm as putting static infront of main(). For a class we must need a context. without creating context we can not execute a program. So for that either we need a main() or a static block.


November 1, 2008 at 1:40 PM


You can not do that because main method should be directly available to JVM., Its not a method is a thread. So for that we need context of the class. So we r giving instruct to jvm as putting static infront of main(). For a class we must need a context. without creating context we can not execute a program. So for that either we need a main() or a static block.


Related Tutorials/Questions & Answers:
java
java  diff bt core java and java
java
java  what is java
Advertisements
Java
Java   Whether Java is pure object oriented Language
java
java  different between java & core java
java
java  explain technologies are used in java now days and structure java
java
java   why iterator in java if we for loop
JAVA
JAVA  how the name came for java language as "JAVA
java
java  what is java reflection
java
java  is java open source
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
java  write a java program using filenotfoundexception
Java
Java  how to draw class diagrams in java
java
java   difference between class and interface
java
java  why multiple inheritance is not possible in java
java
java  explain object oriented concept in java
java
java  is java purely object oriented language
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  what are JAVA applications development tools
java
java  how use java method
java
java  send me java interview questions
java
java  write a program in java to acess the email
java
java  Write a java code to print "ABABBABCABABBA
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  give a simple example for inheritance in java
java
java  give a simple example for inheritance in java
Java
Java  how to do java in command prompt
java
java  Does java allows multiline comments
Advertisements
 

 

 

DMCA.com