Constructor

  1. class Mno
  2. {
  3. int salary;
  4. void Mno()
  5. {
  6. salary=25000;
  7. return;
  8. }
  9. public static void main(String...a)
  10. {
  11. Mno m1=new Mno();
  12. m1.Mno();
  13. System.out.println(m1.salary);
  14. System.out.println(m1);
  15. }
  16. }
  17. Output:
  18. 25000
  19. Mno@15db9742
  1. class Mno
  2. {
  3. int salary;
  4. Mno()
  5. {
  6. salary=25000;
  7. System.out.println(salary);
  8. }
  9. public static void main(String...a)
  10. {
  11. new Mno();
  12. }
  13. }
  14. Output:
  15. 25000
  1. class Pc
  2. {
  3. int salary;
  4. Pc(int s)
  5. {
  6. salary=s;
  7. System.out.println(salary);
  8. }
  9. public static void main(String...x)
  10. {
  11. Pc n1=new Pc(15000);
  12. Pc n2=new Pc(25000);
  13. Pc n3=new Pc(35000);
  14. }
  15. }
  16. Output:
  17. 15000
  18. 25000
  19. 35000
  1. class Npc
  2. {
  3. int salary;
  4. Npc()
  5. {
  6. System.out.println("NPC Invoke");
  7. }
  8. public static void main(String...x)
  9. {
  10. Npc n1= new Npc();
  11. Npc n2= new Npc();
  12. }
  13. }
  14. Output:
  15. Npc Invoke
  16. Npc Invoke

-Webpage Under Development-


| Copyright ©2016 | All Rights Reserved |
| Design by Uves Khan |

Free Web Hosting