Last active
March 9, 2018 16:07
-
-
Save rosuH/1448378791ac75a2100fca2082c5b7d8 to your computer and use it in GitHub Desktop.
Pass parameter from default constructor to Custom constructor.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
public class Main { | |
public static void main(String[] args){ | |
B b = new B(); | |
System.out.println("-----"); | |
B bB = new B(12); | |
} | |
} | |
class B{ | |
public B (){ | |
this(new Random().nextInt()); | |
System.out.println("This is a default constructor passed the parameter "); | |
} | |
public B (int i){ | |
System.out.println("This is a Custom constructor accepted the parameter = " + i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment