Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Demo {
- int a;
- public Demo() { //default constructor
- System.out.println("Default Constructor");
- }
- public Demo(int val) { //constructor overloading
- a = val;
- System.out.println("Overloaded Constructor, Value: " + a);
- }
- public Demo(Demo copy) {
- a = copy.a;
- System.out.println("Copy Constructor, Value: " + a);
- }
- }
- class Pr1a {
- public static void main(String args[]) {
- Demo d = new Demo();
- Demo d1 = new Demo(5);
- Demo d2 = new Demo(d1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement