fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Son kian = new Son();
  13. kian.howOldAmI();
  14. kian.howOldIsMyMother();
  15. }
  16. }
  17. class Mother {
  18. int age = 35;
  19.  
  20. public Mother(String childName){
  21. System.out.println("I'm " + childName + "'s mother and I'm " + age);
  22. }
  23. public Mother(){
  24. System.out.println("Mother is " + age);
  25. }
  26. public void ageAndPrint(int age){
  27. this.age = age;
  28. System.out.println(this.age);
  29. }
  30.  
  31. public void howOldAmI(){
  32. System.out.println("I, Mother; am " + age);
  33. }
  34.  
  35. }
  36.  
  37. class Son extends Mother {
  38. int age = 6;
  39. public Son(){
  40. super("Kian");
  41. System.out.println("Son is " + age);
  42.  
  43. }
  44. void howOldIsMyMother(){
  45. System.out.println("My Mother is " + super.age);
  46. }
  47.  
  48. @Override
  49. public void howOldAmI(){
  50. System.out.println("I am " + age);
  51. super.howOldAmI();
  52. }
  53.  
  54. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
I'm Kian's mother and I'm 35
Son is 6
I am 6
I, Mother; am 35
My Mother is 35