Tutorial 12: Inheritance Getting Started
Code:
Mom.java
package Inheritance;
/**
*
* @author Ankit
*/
public class Mom {
private String strSkinTone;
private String strEyes;
public String getStrEyes() {
return strEyes;
}
public void setStrEyes(String strEyes) {
this.strEyes = strEyes;
}
public String getStrSkinTone() {
return strSkinTone;
}
public void setStrSkinTone(String strSkinTone) {
this.strSkinTone = strSkinTone;
}
}
/**
*
* @author Ankit
*/
public class Mom {
private String strSkinTone;
private String strEyes;
public String getStrEyes() {
return strEyes;
}
public void setStrEyes(String strEyes) {
this.strEyes = strEyes;
}
public String getStrSkinTone() {
return strSkinTone;
}
public void setStrSkinTone(String strSkinTone) {
this.strSkinTone = strSkinTone;
}
}
Child.java
package Inheritance;
/**
*
* @author Ankit
*/
public class Child extends Mom{
}
/**
*
* @author Ankit
*/
public class Child extends Mom{
}
MainInheri.java
package Inheritance;
/**
*
* @author Ankit
*/
public class MainInheri {
public static void main(String[] args) {
Child John = new Child();
John.setStrEyes("Brown");
John.setStrSkinTone("Fair");
System.out.println("John inherited eyes color from his mom: that is:"+John.getStrEyes());
System.out.println("John inherited skintone from his mom and that is: "+ John.getStrSkinTone());
}
}
/**
*
* @author Ankit
*/
public class MainInheri {
public static void main(String[] args) {
Child John = new Child();
John.setStrEyes("Brown");
John.setStrSkinTone("Fair");
System.out.println("John inherited eyes color from his mom: that is:"+John.getStrEyes());
System.out.println("John inherited skintone from his mom and that is: "+ John.getStrSkinTone());
}
}
No comments:
Post a Comment