Share on Google+Share on Google+

vijay
Inheritence
1 Answer(s)      8 years ago
Posted in : Java Beginners

Ads

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
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
java  why java is platform independence? why it does not support multiple inheritence
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
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
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: Single - level inheritance Multi - level inheritance Hierarchical 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 - 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
Garbage Collection Static Variables Stack Heap Java Inheritence
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
Inheritance - Java Beginners
{ System.out.println("Using inheritence example!"); BufferedReader buff = new
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
JDO UNPLUGGED - PART 1
-oriented capabilities of Java. OOPs techniques like Inheritence, polymorphism
Hibernate Book
like inheritence, polymorphism, encapsulation and association. Unfortunately
HibernateBooks
in the business domain are modelled using purely object-oriented notions like inheritence
Tutorials   
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized

Ads

 
Advertisement null

Ads