Overload the default constructor to take a parameter for each attribute and set it

class StudentData
{
   private int stuID;
   private String stuName;
   private int stuAge;
   StudentData()
   {
       //Default constructor
       stuID = 100;
       stuName = "New Student";
       stuAge = 18;
   }
   StudentData(int num1, String str, int num2)
   {
       //Parameterized constructor
       stuID = num1;
       stuName = str;
       stuAge = num2;
   }
   //Getter and setter methods
   public int getStuID() {
       return stuID;
   }
   public void setStuID(int stuID) {
       this.stuID = stuID;
   }
   public String getStuName() {
       return stuName;
   }
   public void setStuName(String stuName) {
       this.stuName = stuName;
   }
   public int getStuAge() {
       return stuAge;
   }
   public void setStuAge(int stuAge) {
       this.stuAge = stuAge;
   }

   public static void main(String args[])
   {
       //This object creation would call the default constructor
       StudentData myobj = new StudentData();
       System.out.println("Student Name is: "+myobj.getStuName());
       System.out.println("Student Age is: "+myobj.getStuAge());
       System.out.println("Student ID is: "+myobj.getStuID());

       /*This object creation would call the parameterized
        * constructor StudentData(int, String, int)*/
       StudentData myobj2 = new StudentData(555, "Chaitanya", 25);
       System.out.println("Student Name is: "+myobj2.getStuName());
       System.out.println("Student Age is: "+myobj2.getStuAge());
       System.out.println("Student ID is: "+myobj2.getStuID()); 
  }
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
constructor overloading different types constructor overloaded constructor overloading in java with example Write an overloaded constructor with parameters to be assigned to the attributes. creating a overloaded constructor in java creating a overloaded constructor overloading constructors in java write an overloaded constructor that will accept a string value to initialize to greeting overloaded constructor. syntax constructor overloading in java Write a Java Program to demonstrate functioning of classes, objects and constructor overloading. java ctor overload WAP in java to deminstrate method overloading and construtor and constructor overloading give an example of constructor overloading in java main method explain constructor overloading with example in java example overload constructor java overloading constructor constructor overloading Overload the method for specific object created from the Constructor Function Function and constructor Overloading, if yes then give an example? Is it possible to perform Function and constructor Overloading, if yes then give an example? Write a java program to demonstrate Constructors, Parameterized Constructors and Constructor Overloading how to display memebrs in overloaded construstor constructor overloading in java overloading constructors java constructor overloading and constructor overrding constructor java overloading java overloading constructors overloaded constructor example all string in overloaded constructur java overloaded constructur java Provide some details and examples of Method and or Constructor Overloading. overloading constructure java instance of a class overloaded constructor how to use the constructor in java using overloaded how to create empty overloading in java create an empty overload in constructor java create overload name period and level in constructor constructor overloading in java program overloading the constructor java overload constructor We are going to use the Student class and complete it by writing a two constructors (overloading the constructor). The first constructor should take first name, last name, grade, and school, then set all the instance variables accordingly. overloaded constructor java example of Initialize Method(record) and using Constructor in netbeans create 4 students with 4 constructor in java java overloaded constructor When overloading a class constructor, the parameter types of the constructors must be different. create student class in overload constructor using java program create a blood bank in overload constructor using java program java can i new another constructor in one Overload constructor java can i new another construct in one Overload construct overloading methods and constructors in java question java program for constructor overloading 2 overload constructor java overload constructor java default constructor and overloading constructor overloaded constructor with encapsulation# overloaded constructor with parameters and encapsulation can constructor be overloaded in java type of contactor in java overload constrcutor java ____method/methods cannot be overridden * constructor method overloa Java Create a class Room with data members as length, breadth and height. Calculate area of 10 Rooms and Display the same. Make use of parameterized constructor, default constructor and this keyword. Create a class Room with data members as length, breadth and height. Calculate area of 10 Rooms and Display the same. Make use of parameterized constructor, default constructor and this keyword. overloaded constructor initialize and find area of a trian overloading constructor initialization of triagles private constructor and overloaded java overloaded constructors java overloaded constructor overloaded constructor in java constructor overload Illustrate Constructor Overloading citing an example. What is a constructor? Illustrate Constructor Overloading citing an example. example code of constructor overloading in java how to write a class with Constructors default and overloaded in java? java constructor overloading how to overload constructor in java Overload the default constructor to take a parameter for each attribute and set it.
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source