Latest Products
Showing posts with label Java Tips. Show all posts
Showing posts with label Java Tips. Show all posts

Inheritance in java



Deriving the base class property to child class. In java we using the keyword extends.

Syntax :
<modifier> class  baseclassname extends childclassname

Example

class First
{
 int a;
 First()
 {
  a=5;
  System.out.println("From class First's constructor ...");
 }
 void hai()
 {
  System.out.println("From class First , a = " + a);
 }
}

class Inheritance  extends First
{
 Inheritance()
 {
  super(); //calling the base class constructor.
 }  
 public static void main(String args[])
 {
  int a=5; 
  First f = new First();
  f.hai();
  System.out.println("From class Inheritance , a = " + 5);
 }
}
 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. TECHBEAN stars - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger