MY mENU


Thursday 9 February 2012

how can we run javaprograme without having main() ?

static block are the blocks which are entertained at the time of class loading means there is no need to execute the code(infact with static block u can run your code without the main()) 
where as the static initializers are the static blocks which are used to initialize the static variables"





Static Methods cannot be overriden, although they can be redeclared/ redifined by a SubClass. So although Static Methods can sometimes appear to be overriddenPolymorphismwill not apply.

for ex:

class abc{
public static void show(){}

}
public class first extends abc {

public static void show(){}

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

the above code will compile fine. here we have redefined the static method show() and not overriding it.

No comments:

Post a Comment