Inheritence

Inheritence

View Answers

November 7, 2008 at 1:03 PM

Hi friend,


There are two forms of inheritance in the Java language. The standard form of inheritance is by extension; a class declares that it extends another class, or an interface extends another interface. In this case, the sub-class or sub-interface inherits all the fields and methods of its parent.

The second special form of inheritance is where classes declare that they implement an interface, which has more limited consequences. When a class implements an interface, it inherits any fields from the parent as final constants, but must provide its own implementation of the interface methods.


Example:

import java.io.*;

class ClassA{

int x;
int y;
int get(int p, int q){
x=p; y=q;
return(0);
}
void Show(){
System.out.println("Value of x:" + x);
System.out.println("Value of y:" + y);
}
}

class ClassB extends ClassA{

public static void main(String args[]) throws IOException{
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter number of x!");
int x= Integer.parseInt(buff.readLine());
System.out.println("Please enter number of y!");
int y= Integer.parseInt(buff.readLine());

ClassA call = new ClassA();
call.get(x,y);
call.Show();
}
void display(){
System.out.println("B");
}

}


------------------------------------------

Visit for more information.

http://www.roseindia.net/java/language/inheritance.shtml

Thanks.









Related Tutorials/Questions & Answers:
inheritence Vs inheritence
inheritence Vs inheritence  what are difference b/w c++ inheritence and java inheritence   Hi Friend, C++ supports Multiple Inheritance while Java does not. Thanks
inheritence in java?
inheritence in java?  what is inheritence and how it work inn java
Advertisements
Java inheritence
Java inheritence  if there are 20 methods in a class if only 2 methods are used for inheritence is it better idea to use inheritence or use other logic
java inheritence
sec... so now create a base class n 4 sub class using inheritence.... like for eg
java multiple inheritence - Java Interview Questions
java multiple inheritence  what are the drawbacks of multiple inheritence due to which it is not used in JAVA?Thanks in Advance.  Hi friend, drawbacks of multiple inheritence due to which it is not used in JAVA
Java inheritence
Java inheritence
Inheritence - Java Beginners
: import java.io.*; class ClassA{ int x; int y; int get(int p, int q){ x=p; y=q; return(0); } void Show(){ System.out.println
Java inheritence - Java Beginners
java
java  why java is platform independence? why it does not support multiple inheritence
Deligation - Java Interview Questions
Deligation  Respected sir/mam kindly inform me how we can implement deligation in java and what is difference between deligation and inheritence thanks
How we learn java
How we learn java  what is class in java? what is object in java? what is interface in java and use? what is inheritence and its type
How we learn java
How we learn java  what is class in java? what is object in java? what is interface in java and use? what is inheritence and its type
How we learn java
How we learn java  what is class in java? what is object in java? what is interface in java and use? what is inheritence and its type
How we learn java
How we learn java  what is class in java? what is object in java? what is interface in java and use? what is inheritence and its type
How we learn java
How we learn java  what is class in java? what is object in java? what is interface in java and use? what is inheritence and its type
multiple inheritance
multiple inheritance  Class A extends Class B but Class A also inherit Super Class Object so it is multiple inheritence give reason in support of your answer
inhertence
inhertence  how many types of inheritence in java according to sun specification?   Hi Friend, Java supports following inheritance types:ADS_TO_REPLACE_1 Single - level inheritance Multi - level inheritance
Interface in JAVA - Java Interview Questions
Interface in JAVA  How interface fulfills all th facilities which is provided by the Mutiple inheritence?   Hi Sanjay, Developers found the flaw available in the Java that it does not support Multiple Inheritance
Java - Development process
.,Inheritence
java - Java Beginners
. * Simple Inheritance * Multilevel Inheritance Simple inheritence : class A { int x; int y; int get(int p, int q){ x=p; y=q; return(0...("B"); } Multilevel Inheritence : class A { int x; int y
interfaces - Java Beginners
{ void hello2(); } For read more information on inheritence visit
question paper - JSP-Servlet
question from each area like inheritence,exception handling.the question has
inheritance code program - Java Beginners
IOException{ System.out.println("Using inheritence example!"); BufferedReader... IOException{ System.out.println("Using inheritence example!"); BufferedReader buff
Java Tutorial
Inheritence Abstract Method & Class Java Interface Java
Inheritance and Composition - Java Beginners
it will compile) return 0; } }   Inheritence using in java... inheritance class TextDemo { int x; int y; int get(int p, int q){ x=p; y=q; return(0); } void Show(){ System.out.println(x
Inheritance - Java Beginners
{ System.out.println("Using inheritence example!"); BufferedReader buff = new
Java Interview Questions - Page 1
: Why Java does not support multiple inheritence ?  Answer: Java... is the output of x<y? a:b = p*q when x=1,y=2,p=3,q=4? Answer: When.... If the statement is rewritten as: x<y? a:(b=p*q); the return value would
Hibernate Book
like inheritence, polymorphism, encapsulation and association. Unfortunately
JDO UNPLUGGED - PART 1
-oriented capabilities of Java. OOPs techniques like Inheritence, polymorphism
HibernateBooks
in the business domain are modelled using purely object-oriented notions like inheritence

Ads