0

Hi,
Can any one say what is the difference between the implicit and explicit?


Thank you,

With Regards,
Prem

3
Contributors
5
Replies
27
Views
7 Years
Discussion Span
Last Post by tong1
0

Explicit means done by the programmer.
Implicit means done by the JVM or the tool , not the Programmer.

For Example:
Java will provide us default constructor implicitly.Even if the programmer didn't write code for constructor, he can call default constructor.

Explicit is opposite to this , ie. programmer has to write .

Edited by new_programmer: Unknowingly submitted

-1

Hi new_programmer,

Can you tell me what is default constructor and how to use the default constructor in the program with example?

Thank you,

0

Hi new_programmer,

Can you tell me what is default constructor and how to use the default constructor in the program with example?

Thank you,

1

Default constructor is the constructor with no arguments requested. It is called implicitly when creating an instance.

import java.io.*;

public class DefaultConstructor {
    
    public DefaultConstructor() {
    	System.out.println("I am Default with no arguments.");
    	}      

    public static void main(String[] args) {
        DefaultConstructor d = new DefaultConstructor();
    }
}

output:
I am Default with no arguments.

1

One thing you have to remember:
If you have defined some non-default constructors, the compiler will not implicitly provide a default constructor. If you need a default one you'd better define one. Otherwise it wouldn't pass compiling. For example, the following code leads to an error message for line 10:unsolved symbol

import java.io.*;

public class DefaultConstructor {

    public DefaultConstructor(String s) {
    	System.out.println("I am Not Default with no arguments. " + s );
    	}      

    public static void main(String[] args) {
        DefaultConstructor d = new DefaultConstructor();
    }
}
Votes + Comments
Nice Example
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.