Advertisement
zoro-10

pr1a.java :

Mar 30th, 2024
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. class Demo {
  2.  
  3.   int a;
  4.  
  5.   public Demo() { //default constructor
  6.     System.out.println("Default Constructor");
  7.   }
  8.  
  9.   public Demo(int val) { //constructor overloading
  10.     a = val;
  11.     System.out.println("Overloaded Constructor, Value: " + a);
  12.   }
  13.  
  14.   public Demo(Demo copy) {
  15.     a = copy.a;
  16.     System.out.println("Copy Constructor, Value: " + a);
  17.   }
  18. }
  19.  
  20. class Pr1a {
  21.  
  22.   public static void main(String args[]) {
  23.     Demo d = new Demo();
  24.     Demo d1 = new Demo(5);
  25.     Demo d2 = new Demo(d1);
  26.   }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement