Why we write the Static keyword in Java program?

Asked on September 24, 2014
while writing the code of java we use static keyword,

class add{
       public static void main(String [] args)
                 int a=3, b=4;
                 int c= a+b;
anyone please tell me why we use static?

Replied on October 08, 2014
To start the main method use use Static keyword... its may be woks a constructor.

Replied on October 08, 2014
1)public:Public is access specifier means anyone can access/invoke it such as JVM(Java Virtual Machine.
2).static:Static keyword allows main() to be called before an object of the class has been created.
This is neccesary because main() is called by the JVM before any objects are made.Since it is static so directly invoked from class.

Write Answer

©2023 concretepage.com | Privacy Policy | Contact Us