Successfully reported this slideshow.

Constructor Overloading in java

526 views

Published on

WAP on constructor overloading in java

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

Constructor Overloading in java

  1. 1. //Ques. 9 WAP on constructor overloading. class Student { privateintrollNumber; private String name; public Student() { System.out.println("n Inside Default Constructor"); rollNumber=0; name="Unknown"; } public Student(introllNumber,String name) { System.out.println("n Inside Overloaded Constructor"); this.rollNumber = rollNumber; this.name=name; } public void displayStudent() { System.out.println(" Name = "+name); System.out.println(" Roll No. = "+rollNumber);
  2. 2. } } classConstructorOverLoad { public static void main(String arg[]) { Student s1 = new Student(7448264,"Ultimate Virus"); s1.displayStudent(); Student s2 = new Student(); s2.displayStudent(); } }
  3. 3. OUTPUT:-

×