0
How to make overloading code from this codes?
//single inherintance class Parent { protected String name;//data member in superclass Parent()//constructor in super { name="Mother"; } } //subclass class Child extends Parent { String name;//data member in subclass Child()//constructor { super();//call constructor in superclass name="Daughter"; } void viewParent() { System.out.println("I am "+super.name);//parent } void viewChild() { System.out.println("I am "+this.name);//child } public static void main(String args[]) { Child objc=new Child(); objc.viewParent(); objc.viewChild(); } }
1 Antwort
- 1
Example:
Parent()
{
this.name="mother";
}
Parent(String motherName)
{
this.name=motherName;
}
Like this,
Instead of default values, you can set names for other...
You can add overloading constructor implementation for Parent("motherName", "father Name");