Default Constructor in Java

0 votes

Which of the following two is the default constructor of Java?

public Test() {
   this.name = "";
   this.credits = 0;
   this.hours = 0;
}

public Test(String name, int credits, int hours) {
   this.name = name;
   this.credits = credits;
   this.hours = hours;
}
Please explain the difference between them as well.
Jun 19, 2018 in Java by v.liyyah
• 1,300 points
1,194 views

1 answer to this question.

0 votes

Well, none of these is the default constructor of Java. When you say default, that means you don’t have to explicitly define it.

A default constructor is implicitly called by the JRE if there is no constructor is defined for a class. For your example, a default constructor will look something like below:

public Test()
{}

answered Jun 19, 2018 by geek.erkami
• 2,680 points

Related Questions In Java

0 votes
0 answers

What is the default access specifier in Java?

I just started reading a Java book ...READ MORE

Apr 26, 2022 in Java by Rahul
• 3,380 points
438 views
0 votes
1 answer

What is the default priority of a thread in java?

By default, in Java, when a thread ...READ MORE

answered Nov 29, 2023 in Java by Zoya
451 views
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 81,391 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,220 points
3,619 views
0 votes
1 answer

Can Abstract Class have a Constructor?

Yes, an abstract class can have a ...READ MORE

answered May 11, 2018 in Java by sharth
• 3,370 points
1,188 views
0 votes
2 answers

How to call one constructor from another in Java?

public class Cons { public static Cons ...READ MORE

answered Jul 24, 2018 in Java by Akrati
• 3,190 points
1,579 views
0 votes
1 answer

How to set a timer in Java?

To work on timer in java, you ...READ MORE

answered May 16, 2018 in Java by Daisy
• 8,140 points
1,231 views
0 votes
2 answers

When and how to use Super() keyword in Java?

super() is used to call immediate parent. super() can be ...READ MORE

answered Jul 9, 2018 in Java by Sushmita
• 6,920 points
1,883 views
0 votes
1 answer

Sorting an ArrayList in Java

You can easily do this by simply ...READ MORE

answered May 5, 2018 in Java by geek.erkami
• 2,680 points
2,208 views
0 votes
1 answer

Why the main() method in Java is always static?

As you might know, static here is ...READ MORE

answered May 9, 2018 in Java by geek.erkami
• 2,680 points
2,116 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP