Posts Tagged ‘Java OO Programs’

Java Program to show Overloading Constructors – Q21

January 11, 2009 Leave a comment

Q21: Java Program to show overloading constructors

Constructors are used to create instances of an object and can be overloaded by creating more than one Constructor in a class with same name but having different signatures.

class Emp_class{
	private String name;
	private int salary;
	public Emp_class(){
		name = "Manoj Pandey";
		salary = 10500;
	public Emp_class(String n, int s){
		name = n;
		salary = s;
	public Emp_class(Emp_class Oemp){
		name =;
		salary = Oemp.salary;
	public void show(){
		System.out.println("\n Name: " + name);
		System.out.println(" Salary: " + salary);

class ctor_ovld{
	public static void main(String args[]){
		Emp_class Oe1 = new Emp_class();;
		Emp_class Oe2 = new Emp_class("Nitin", 25050);;
		Emp_class Oe3 = new Emp_class("Bhuwanesh", 30050);;

		Emp_class Oe4 = Oe2;;

… from College notes (BCA/MCA assignments):