Saturday, June 25, 2016

Simple Inheritance in Java

A simple program that I wrote in Java to show how the concepts of inheritances works. This program will greet the user three times when we assign a name of the user in a string. The code is very easy to understand and learn ideal for those that are new in Java programming.

 Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

Simple_Inheritance.java


package hello;


class hello_world{ 

 public void greet2(String user){
        System.out.println("Hello " + user + " How are you?");
        System.out.println();
  }
 public void greet3(String user){
        System.out.println("Kamusta ka " + user + " Welcome to Philippines.");
        System.out.println();
        System.out.println("\t End of Program");
     }
 
}


public class Simple_Inheritance extends hello_world {
 public void greet1(String person1){
    System.out.println("\t Simple Inheritance in Java");
    System.out.println();
        System.out.println("Welcome " + person1 + " to our home.");
        System.out.println();
  }
 public static void main(String args[]){
 String name="Jake R. Pomperada";
 
 Simple_Inheritance person = new Simple_Inheritance();
 person.greet1(name);
 person.greet2(name);
 person.greet3(name);
 
  }
}


 

No comments:

Post a Comment