0
Important question
It the class must always have a default constructor??
14 Respostas
+ 3
Every class written in java by default has its parent class 'Object'. So when ever you create a new instance of your class it will directly calls it's parents class constructor .. so the answer for your question is not required. But if you want your own implementation for your constructor.. you need to create one which will override your parent class constructor.
+ 4
You can try it yourself in code Playground
+ 2
Benjamin JĂŒrgens So it is false?
+ 2
"You don't have to provide any constructors for your class, but you must be careful when doing this. The compiler automatically provides a no-argument, default constructor for any class without constructors. This default constructor will call the no-argument constructor of the superclass. In this situation, the compiler will complain if the superclass doesn't have a no-argument constructor so you must verify that it does. If your class has no explicit superclass, then it has an implicit superclass of Object, which does have a no-argument constructor."
https://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html
+ 2
Thanks all of you
+ 2
Default constructor will be added by the compiler if you create an object in that class
+ 2
there's no need for that ... If u don't include that compiler automatically creates default constructor
+ 1
Benjamin JĂŒrgens :) i want help just tell me it is true or false?
+ 1
public class Program
{
public static void main(String[] args) {
}
}
No constructor
+ 1
Yes, a program has its own default constructor which is called automatically at the time of object creation.
For example:-
Like we have a program of class name Counter
Then,as we create a object(object name- count)of class Counter a default constructor will be called by itself.
e.g.- Counter count=new Counter();
You can see that in above object creation statement, at the last Counter() constructor is called.
+ 1
Not necessary when you are not calling for a custom class. And complier also creates a default constructor from its own when it doesn't get the default constructor
0
You don't have to provide any construction for your class , but you must be careful when doing this.
- 3
Good for 33 330 l. 0%l0....