Home > DeveloperSection > Blogs > Super method in java

Super method in java


Java Java 
Ratings:
0 Comment(s)
 2619  View(s)
Rate this:

Super method in java

It is a keyword in java used to access members of a class inherited by the class in which it appears. Super method is use to transfer the message or data to their super class (it refers to a class from which a particular class (subclass) is derived.) constructor to initialize their data.

Example
this is the simple demonstration, how to use super keyword in java.

Class Person
{
                String name,address;
                int age;
               
                Person(String userName,String add, int userAge)
                {
                                name=username;
                                address=add;
                                age=userAge;
                }

                void show()
                {
                                System.out.println(name);
                                System.out.println(address);
                                System.out.println(age);
                }
}

Class Employee extends Person
{
                int empCode,empSal;
               
                Employee(String name, String add, int u_age,int code,int sal)
                {
                                Super(name,add,age):
                                empCode=code;
                                empSal=sal;
                                void show1()
                                {
                                                show();
                                               
                                                System.out.println(code);
                                                System.out.println(sal);
                                }

                                Public Static void main(Strings args[])
                                {
                                                Employee e=new Employee(“davis”,”newHoles”,27,001,4000);
                                                e.show1();
                                }
  }
                                               


Don't want to miss updates? Please click the below button!

Follow MindStick