-
problem with main() method
The problem is related with the decleration of the main method.
The JVM should match the signature of the main method as
public static void main( String[] args ). It is mentioned everywhere that
if this signature does not match, the program will not complie. Still, the
following code works perfectly:
-----------------------------------------------------------------
class Strange
{
private static void main(String[] args)
{
System.out.println("Hello Strange!");
}
}
class Ex extends Strange
{
private static void main(String[] args)
{
Strange.main( args ) ;
System.out.println("Hello Ex!");
}
}
----------------------------------------------------------------
Even if I use a single class and declare a main method as private, the code
complies and runs fine.
Please post your reply at my mail address: vbbr@usa.net.
Thanx.
Vikas
-
Re: problem with main() method
It doesn't work. Since , the Ex class tries to call a private method main
of the class strange !
But any way , its not rule that the main mathod has to be public.
But the rule is ,
(1)main has to be static
(2)string array argument has to be there.
(3)the class that contains main has to be the same name as
the source file. if it is not so, it will compile but will not
run.
"Vikas Babbar" <vbbr@usa.net> wrote:
>
>The problem is related with the decleration of the main method.
>The JVM should match the signature of the main method as
>public static void main( String[] args ). It is mentioned everywhere that
>if this signature does not match, the program will not complie. Still, the
>following code works perfectly:
>
>-----------------------------------------------------------------
>class Strange
>{
> private static void main(String[] args)
> {
> System.out.println("Hello Strange!");
> }
>}
>
>class Ex extends Strange
>{
> private static void main(String[] args)
> {
>
> Strange.main( args ) ;
> System.out.println("Hello Ex!");
> }
>
>}
>
>----------------------------------------------------------------
>
>Even if I use a single class and declare a main method as private, the code
>complies and runs fine.
>
>Please post your reply at my mail address: vbbr@usa.net.
>
>Thanx.
>
>Vikas
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks