class Sample
{
final strictfp synchronized static public void main(String... rgukt)
{
System.out.println("WELCOEM TO SESSION");
}
}
Which of the follwoing are Valid main method declarations?
1. public static void Main(String args[])
2. public static int main(String []args)
3. public static void main(String args)
4. public final strictfp synchronized void main(String []args)
5. public static final strictfp synchronized void main(String args[])
6. public static void main(String... args)
In which of the above cases we will get CTE
In which of the above cases we will get RTE
Special Cases:
Case1:
Overloading of the main method is possible or not
class Sample
{
PSVM(String []a)
{
SOP("String[]");
}
psvm(int []a)
{
SOP("int[]");
}
}
Case 2:
Inheritance applicable to main method
Case 3:
Overriding concept applicable to main method
Q: Without writing main() method is it possbile to print
some stmts on to the concole?
Ans: Yes we can print by using static block
This rule 1.6 version 1.7 main method mandatory
System.out.println("MSG");
class Test
{
static String s="OOPS";
}
Test.s.length();
- Test is a class name
- 's' is a static variable present in Test class of type String
- length() is a method presnt in String class
class System
{
static PrintStream out;
}
Sytem.out.println("WELCOME");
- System is class present in java.lang package
- 'out' is a static variable present in System class of type PrintStream
-println() is a method present in PrintStream class