The Artima Developer Community
Sponsored Link

Java Buzz Forum
Differences between Default constructor and no argument constructor in java

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
Differences between Default constructor and no argument constructor in java Posted: Mar 15, 2016 10:22 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Differences between Default constructor and no argument constructor in java
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement
Differences between default constructor and no argument constructor


Default Constructor in java:

  • When we write a class without any constructor then at compilation time java compiler creates a default constructor in our class.
  • The accessibility modifier of the default constructor is same as accessibility modifier of class.
  • The allowed accessibility modifier are public and default.
  • Default constructor added by java compiler this constructor does not have anything except super(); call.





  1. package constructor;
  2. public class A {
  3.   
  4.  
  5. }


  1. package constructor;
  2. public class A {
  3.  
  4.     A(){
  5.         
  6.         super();
  7.  
  8.     }
  9.  
  10. }

  • If our class have any constructor then java compiler does not create default constructor

No-argument Constructor in java:

  • As a developer we can create our own constructor with no arguments is known as no-argument constructor.
  • It can have all four accessibility modifiers as it is defined by developer.
  • So allowed accessibility modifiers are public, private, protected and default
  • It can have logic including super call.


  1. package constructor;
  2. public class A {
  3.  
  4.     A(){
  5.         
  6.   super();
  7.   System.out.println("no -argument constructor");

  8.     }
  9.  
  10. }

  • The common point between default and no-argument constructor 
  • Both does not have any arguments.
  • And one more point we need to remember that in no-argument constructor also by default first statement will be super() call which is added by java compiler if it does not have.

Read: Differences between Default constructor and no argument constructor in java

Topic: EJB Deployment Descriptor Example Previous Topic   Next Topic Topic: Enabling small batches with cloud native

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use