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


Thank you,

With Regards,
Prem

Recommended Answers

All 5 Replies

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 .

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,

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,

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.

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();
    }
}
commented: Nice Example +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.