I would like to know whether we can call a method from class rather than from static main method.While executing this code I've got error stating:
D:\Downloads\PRO>javac start.java
start.java:9: error: illegal start of type
this.method();
^
start.java:9: error: ';' expected
this.method();
^
start.java:9: error: invalid method declaration; return type required
this.method();
^
3 errors.
Also I would like to know when a compiler starts whether it invokes the static main method or whether it invokes the class which contains the static main method.Could anyone help me.
D:\Downloads\PRO>javac start.java
start.java:9: error: illegal start of type
this.method();
^
start.java:9: error: ';' expected
this.method();
^
start.java:9: error: invalid method declaration; return type required
this.method();
^
3 errors.
Code:
import java.io.*;
class start
{
public static void main(String args[])
{
System.out.println("STARTING JAVA PROGRAM");
}
finish f=new finish();
f.method();
}
class finish
{
public void method()
{
System.out.println("FINISHING JAVA PROGRAM");
}
}