answersLogoWhite

0


Best Answer

No. if you wish to create an object that you plan on using in a java program then the answer is NO. You cannot initialize an object of a Java class without calling the constructor.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you initialize an object without constructor in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can you use business logic in constructor with example in java?

No. Logic should never go in a constructor; constructors should only be used to instantiate and initialize object data.


Why constructor in Java doesn't have any return type?

The constructor of a Java class is not an ordinary method. Its purpose is not to return any value. The purpose of the constructor is to instantiate the class which it does. Since, the purpose of a constructor is only to instantiate and initialize its class and not anything else, it does not have a return type. All it does is creates an object of that class.


What is a constructor and its mandatory to use constructor in a class?

Constructor is a special block of code similar to the method that is used to initialize the state of objects. If you do not define a constructor in a class, Java compiler automatically put a default constructor in the class.


What is a constructoris it mandatory to use constructor in a class?

You always should define default constructor for your class. You must also define a copy constructor for your class if there are any pointers in the class. While it is not mandatory, failure to provide a default constructor can result in bad behavior, and failure to provide a copy constructor when you have pointers in the class will result in bad behavior. For example, without a default constructor, the compiler will not fully initialize the attributes of the class. It will initialize the virtual function table, and call base class constructors, but that is all - the attributes could be random garbage. For another example, without a copy constructor, the compiler will generate one that simply makes a bit wise copy of the attributes. If these attributes contain pointers, then you have two pointers to the same object, not necessarily a good thing, especially if one of them get "deleted".


When constructor function are called in java?

Constructors are called during object creation.

Related questions

Can you use business logic in constructor with example in java?

No. Logic should never go in a constructor; constructors should only be used to instantiate and initialize object data.


Why constructor in Java doesn't have any return type?

The constructor of a Java class is not an ordinary method. Its purpose is not to return any value. The purpose of the constructor is to instantiate the class which it does. Since, the purpose of a constructor is only to instantiate and initialize its class and not anything else, it does not have a return type. All it does is creates an object of that class.


What is a constructor and its mandatory to use constructor in a class?

Constructor is a special block of code similar to the method that is used to initialize the state of objects. If you do not define a constructor in a class, Java compiler automatically put a default constructor in the class.


What is a constructoris it mandatory to use constructor in a class?

You always should define default constructor for your class. You must also define a copy constructor for your class if there are any pointers in the class. While it is not mandatory, failure to provide a default constructor can result in bad behavior, and failure to provide a copy constructor when you have pointers in the class will result in bad behavior. For example, without a default constructor, the compiler will not fully initialize the attributes of the class. It will initialize the virtual function table, and call base class constructors, but that is all - the attributes could be random garbage. For another example, without a copy constructor, the compiler will generate one that simply makes a bit wise copy of the attributes. If these attributes contain pointers, then you have two pointers to the same object, not necessarily a good thing, especially if one of them get "deleted".


Variable lnitialization in java language?

I suppose you want to ask about variable initialization.Java initialize its variables in its constructor.


What is use of constructor in java?

Constructor is used to do something (written in constructor) immediately after object creation.


How do you initialize variable?

initialize simple types: int i = 0; initialize objects: Object o = null; (in java)


Why can't declare construtor as a static final abstract?

Because of the following reasons:static - If a constructor is static, an object instance cannot invoke it to initialize itself (Because static members are not linked to an object)abstract - because an abstract class cannot be instantiated and hence it will not have a constructor. If you make a concrete class's constructor abstract - it cannot be instantiated. eitherways it makes no sensefinal - a constructor cannot be final (thats the way java is designed)


When constructor function are called in java?

Constructors are called during object creation.


What is the function of this in java?

this in java is a keyword that refers to the current object of the class. It is also used in constructor overloading when you want to invoke one constructor from another within the same class.


Does Java support copy constructor?

No. Java does not support copy constructor


What is need of constructor in java class or what is it's importance?

A constructor is automatically invoked whenever an object is created. The relevance of this is that the programmer of a class can ensure that the object is initialized properly - for example, that certain fields have sensible values - without having to rely on another programmer, who uses the class, who may, or may not, initialize it in the expected way. A constructor may also be used to simplify object creation. For example, say you have a class, Complex, with two data items (fields) called "real" and "imaginary". Without a constructor, to create an object and assign it a value, you would have to write something like: x = new Complex(); x.setReal(5.0); x.setImaginary(2.0); Or perhaps: x = new Complex(); x.setValues(5.0, 2.0); But with a constructor, this can be combined into a single step: x - new Complex(5.0, 2.0);