Skip to content

Instantly share code, notes, and snippets.

@rosuH
Last active March 9, 2018 16:07
Show Gist options
  • Save rosuH/1448378791ac75a2100fca2082c5b7d8 to your computer and use it in GitHub Desktop.
Save rosuH/1448378791ac75a2100fca2082c5b7d8 to your computer and use it in GitHub Desktop.
Pass parameter from default constructor to Custom constructor.
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