answersLogoWhite

0

The compiler places a default no-arg constructor in any java class that does not have an explicit constructor coded into it.

for ex:

public class Car {

...

...

//lots of code but no constructor

}

In the above case, the compiler will place the below constructor into the code:

public Car() {

super();

}

But, if you have a constructor in your class that takes arguments then the compiler will not put the default constructor.

Ex:

public class Car {

public Car(String name){

...

}

...

//lots of code

}

Above, we have a Car constructor that takes a string name as argument. so, the compiler wont put the default constructor in the code.

now, if you try to do:

Car obj = new Car();

you will get an error because this constructor is not defined.

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

Why am I getting Java unreported exception while compiling my class?

It may be because you are using inheritance and your super class constructor has a throws clause in its declaration. If your super class has a throws clause in its constructor declaration, you must do the same in your child class constructor in order to eliminate this compiler error.


Is constructors throws exception in C plus plus?

We must throw an exception from constructor in C++, but remember that in case of exception in Ctor, destructor will not be executed and you may have memory leaks. SO make sure all the data members must clean up their mess own. e.g. use smart pointers so in case of excpetion memory will released to free storage.


How does total drama action end?

The Way Total Drama Action Ends Is Owen Wins By Default. He wins a million dollars and throws ANOTHER ending party. Beth wins


What is checked exception?

A compiler for the Java programming language checks, at compile time, that a program contains handlers for checked exceptions, by analyzing which checked exceptions can result from execution of a method or constructor. For each checked exception which is a possible result, the throws clause for the method or constructor must mention the class of that exception or one of the superclasses of the class of that exception. This compile-time checking for the presence of exception handlers is designed to reduce the number of exceptions which are not properly handled.


When a neighbor guy throws mean words to you for no reason does it mean he likes you or he hates you?

1. Maybe, he's a nut case


Piggy then tries to reason with jacks group what is the outcome for piggy?

one of jacks group throws a big rock off the mountain and lands on Piggy's head and dies.


How do you know if guy in your street likes you?

he always throws hint if he looks and smiles he likes you and on day he is just going to just walk up and ask you a question for no reason at all


What are 10 funny reasons to play dodgeball?

One reason is that when you are playing dodgeball then when someone is not looking and they're back is turned to you its kind of funny when someone just throws the ball


What is the spanish word for throws?

Tira. as in "he throws an object"


Which is the better average10 of 15 free throws or 8 of 10 free throws?

8 of 10 free throws


Who throws the ball in softball?

The pitcher throws the ball to the batters, but everyone throws the ball at some point or another.


Who throws the ball in football?

The quarterback throws the football in football