answersLogoWhite

0


Best Answer

You may know that static methods in Java are executed even before the constructor of that class are called.

Similarly, since the main method is static it gets executed first even before the others methods of the class are called. Since it is being called before the constructor, logically speaking you cannot have objects of that class.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: In java how the class containing main is executed with out creating an object?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Is Instantiation is the process of creating an object from a class?

yes


What is meant by instancing a class?

The class can be considered a template to create objects. When you create an object, you create it on the basis of the specified class - the object is an instance of the class, and the act of creating the object is also known as "instantiating" the class.


When are class methods appropriate?

Static methods or class methods are usually used when you want functionality to be executed without creating an instance of the class where that piece of code resides.


What is instance method?

An instance method is nothing but a normal java method. They can be invoked only by creating an object of the class that contains the method definition. Unlike static methods that can be invoked without creating an object of the class.


What is an object in java and is it useful in calling a method?

Objects are very useful in calling a method because they inherit the whole class of the object in the RAM to be executed. And, so a person can each & every method of the class.


Difference between object declaration and object creation?

Declaration of the object involves only creating the reference variable to the object. Example: class SampleClass{ } Object Declaration: SampleClass obj1; Object Creation: Creating an object involves use of new keyword and actually allocating memory for that object. SampleClass obj2 = new SampleClass ();


What contains the roles and definition that use for creating and modifying object class and attributes within active direct?

The Active Directory is what contains the roles and definitions. This is what creates and modify object class and attributes.


Is it true that class variables can be assessed without creating an object of the class?

Yes, if the variable is static. When a variable is static, is associated with the class itself and not any particular object (though it can be accessed through an object as well). An example is shown below: class A { static int k = 5; } ... System.out.println(A.k);//5


What is the purpose of constructor in object oriented programming?

A constructor in a class is one of the first pieces of code to be executed when you instantiate a class. The purpose of constructors is to have code that initialize the class and prepare the variables that may be required by the class...


What is need of static method?

If you need to access a method without creating an object of corresponding class, it need to be a static method.


Explain instantiation of objects in c plus plus?

Instantiation of a class literally means creating an instance of a class. This is the process of allocating memory for an object that you can use in your program.


Why is class called an object factory?

A factory class is a class that uses the factory method pattern. Factory method pattern is a creational pattern that uses factory methods to deal with the problem of creating objects without having to specify the exact class of the object that will be created. Google for more info.