Java code,java,Example,Tutorials,Syntax,Hibernate,Jsp, Servlet, FileHeadling,Java or Core Java Tutorial or Java Programming Tutorial is a widely used robust technology. learning of java from basic questions like what is java tutorial, core java, where it is used, what type of applications are created in java and why use java.

Search This Blog

Sunday, 28 August 2016

Inheritance in Java

Inheritance in Java


Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object.
The idea behind inheritance in java is that you can create new classes that are built upon existing classes. When you inherit from an existing class, you can reuse methods and fields of parent class, and you can add new methods and fields also.
Syntax
  public class vipul
      {
      }
 public class Agravat extends vipul
      {
      }



The extends keyword indicates that you are making a new class that derives from an existing class.
In the terminology of Java, a class that is inherited is called a super class. The new class is called a subclass.
               class vipul{ 
                      float salary=200
                      } 
class Agravat extends vipul
      {
          int bonus=100;  
               public static void main(String args[]){  
                       Agravat A=new Agravat();  
                            System.out.println("Programmer salary is:"+A.salary);  
                            System.out.println("Bonus of Programmer is:"+A.bonus); 
      }  
 }  
OUTPUT
Programmer salary is:200
"Bonus of Programmer is:100
Share:

Agravat &Google

Total Pageviews

Blog Archive

vipul c.Agravat . Powered by Blogger.

myjava

myjava
java

myimg

myimg
good

Translate

Recent Posts

Unordered List

Definition List

Pages

Theme Support