• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How this could be possible??

 
Sandeep Sachan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, friends,
actually





why this particular code is not generating any compile time and runtime error...

please give me some concrite reason.

waiting for your reply....
 
Amit M Tank
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What makes you think it will give Compile time errors? An Abstract class can contain concrete methods. Also You don't need to instantiate an Object in order to invoke the static methods of the class.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amit M Tank:
...An Abstract class can contain concrete methods...

And is not required to contain any abstract methods.
 
Rafael Souza
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All in all, there�s no need to be surprised when this code compiles and runs successfully!

(Hi, I�ve just signed into this forum. Welcome me )
 
Sandeep Sachan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, thnks for your attention,
But Still a query i mean, hwy Java allows abstract class which contains main method. because if i havce the following code then it will not allow me to create the instance of the class.
 
Manfred Klug
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sandeep Sachan:
because if i havce the following code then it will not allow me to create the instance of the class.
You don't need an instance to call a static method.
 
Jeremy Botha
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because static methods don't require their defining class to be instantiated as an object before you can access and execute the methods.

As stated above, the syntax of the class you posted above is absolutely fine.

J
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic