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.shtmlThanks.
Related Tutorials/Questions & Answers:
inheritence Vs inheritenceinheritence Vs inheritence what are difference b/w c++
inheritence and java
inheritence
Hi Friend,
C++ supports Multiple Inheritance while Java does not.
Thanks
Advertisements
Java inheritenceJava 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 Questionsjava 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
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
javajava why java is platform independence?
why it does not support multiple
inheritence Deligation - Java Interview QuestionsDeligation 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 javaHow 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 javaHow 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 javaHow 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 javaHow 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 javaHow 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 inheritancemultiple 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
inhertenceinhertence 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 QuestionsInterface 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 - 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
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
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
HibernateBooks in the business domain are modelled using purely object-oriented notions like
inheritence