Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Hierarchy in java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Lokesh
Hierarchy in java
1 Answer(s)      4 years and 5 months ago
Posted in : Java Beginners


Design a vechicle class hierarchy in java?

Advertisement
View Answers

August 7, 2010 at 10:29 AM


Hi Friend,

Try the following code:

class Vehicle {
void test(){}
}
class Bus extends Vehicle{
void test()
{
System.out.println("I am a bus");
}
}
class Car extends Vehicle{
void test()
{
System.out.println("I am a car");
}
}
class Bike extends Vehicle{
void test()
{
System.out.println("I am a bike");
}
}
public class Polymorphism{
public static void main(String[]args){
Vehicle[] v = new Vehicle[3];
v[0]= new Bus();
v[1]=new Car();
v[2]=new Bike();
for(int i=0;i<v.length;i++){
v[i].test();
}

}
}

Thanks


Related Tutorials/Questions & Answers:
Java AWT event hierarchy
Java AWT event hierarchy  What class is the top of the AWT event hierarchy?  The java.awt.AWTEvent class is the highest-level class in the AWT event-class hierarchy
Hierarchy in java - Java Beginners
Hierarchy in java  Design a vechicle class hierarchy in java?  Hi Friend, Try the following code: class Vehicle { void test(){} } class Bus extends Vehicle{ void test() { System.out.println("I am a bus
Advertisements
Java AWTException Class Hierarchy Diagram
Java AWTException Class Hierarchy Diagram In this section we will discuss about the class hierarchy of AWTException Class in Java. This class extends... exception. A Hierarchy diagram of this exception class is given below
Java AlreadyBoundException Class Hierarchy Diagram
Java AlreadyBoundException Class Hierarchy Diagram In this section we will discuss about the class hierarchy of AlreadyBoundException Class in Java... binding. A class hierarchy diagram is given below : Constructor Detail
Java ApplicationException Class Hierarchy Diagram
Java ApplicationException Class Hierarchy Diagram In this section we will discuss about the class hierarchy of ApplicationException Class in Java... the application level exceptions between ORBs and stubs. A class hierarchy diagram
Java ActivationException Class Hierarchy Diagram
Java ActivationException Class Hierarchy Diagram In this section we will discuss about the class hierarchy of ActivationException Class in Java. This class... this general exception. Class hierarchy diagram is given below : Constructor Detail
Java BackingStoreException Class Hierarchy Diagram
Java BackingStoreException Class Hierarchy Diagram In this section we will discuss about the class hierarchy of BackingStoreException Class diagram in Java. This class extends the java.lang.Exception class. This exception is generally
Java CertificateException Class Hierarchy Diagram
Java CertificateException Class Hierarchy Diagram In this section we will discuss about the javax.security.cert.CertificateException class hierarchy diagram... hierarchy diagram is given below : Constructor Detail Constructor
Java ClassNotFoundException Class Hierarchy Diagram
Java ClassNotFoundException Class Hierarchy Diagram In this section we will discuss about the java.lang.ClassNotFoundException class hierarchy diagram.... ClassNotFoundException class hierarchy diagram is given below
Java AclNotFoundException Class Hierarchy Diagram
In this section we will discuss about the class hierarchy of AclNotFoundException Class in Java. This class extends the java.lang.Exception class... Control List) which has no existence. Hierarchy of this class is shown
Java BadBinaryOpValueExpException Class Hierarchy Diagram
Java BadBinaryOpValueExpException Class Hierarchy Diagram In this section we will discuss about the BadBinaryOpValueExpException diagram in Java... is being given below which demonstrates the hierarchy of this class : Constructor
Java BadAttributeValueExpException Class Hierarchy Diagram
Java BadAttributeValueExpException Class Hierarchy Diagram In this section we will discuss about the BadAttributeValueExpException Class diagram in Java... given below which demonstrates the hierarchy of this class : Constructor
Java BadStringOperationException Class Hierarchy Diagram
Java BadStringOperationException Class Hierarchy Diagram In this section we... diagram in java. This class extends the java.lang.Exception class. When in a query... then BadStringOperationException exception is generated. Class Hierarchy diagram is given
Java BrokenBarrierException Class Hierarchy Diagram
Java BrokenBarrierException Class Hierarchy Diagram In this section we... in java. This class extends the java.lang.Exception class. BrokenBarrierException... upon it. A class hierarchy diagram is given below : Constructor Detail
Java BadLocationException Class Hierarchy Diagram
Java BadLocationException Class Hierarchy Diagram In this section we will discuss about the javax.swing.text.BadLocationException class diagram in Java. This class extends the java.lang.Exception class. BadLocationException exception
ascending order of a data hierarchy
ascending order of a data hierarchy  The ascending order of a data hierarchy is 1. Bit-byte-record-field-file-database 2. Byte-bit-field-record-file-database 3. Byte-bit-record-file-field-database 4. Bit-byte-field-record-file
hierarchy UML class diag
hierarchy UML class diag   Shape Square Circle Rectangle class Shape { string name; public: Shape(string); virtual void ToString(); virtual void Area()=0; }; class Square : public Shape { double side; public
Spring MVC Controller hierarchy
Spring MVC Controllers - Controllers hierarchy in Spring MVC      Controllers hierarchy in Spring MVC In this we will will understand the controllers hierarchy in Spring MVC Module
Filter Implementation In flexible hierarchy Tree Viewer
Filter Implementation In flexible hierarchy Tree Viewer    I am implementing a tree viewer using flexible hierarchy Tree Viewer. I followed... to add filter to this tree viewer. How to implement filter in flexible hierarchy
Filter Implementation In flexible hierarchy Tree Viewer
Filter Implementation In flexible hierarchy Tree Viewer    I am implementing a tree viewer using flexible hierarchy Tree Viewer. I followed... to add filter to this tree viewer. How to implement filter in flexible hierarchy
Java Exception Class Hierarchy Diagram
In this section we will discuss about the hierarchy of java.lang.Exception class. The class Exception and its subclasses are defined in such a way.... An image given below explains the hierarchy of java.lang.Exception class
java - Java Interview Questions
Java io package hierarchy   What is the hierarchy for Java io Package
Java I/O
Java I/O   What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy
Java fundamentals
Java fundamentals  Why Java uses Singly rooted hierarchy
Object Class Methods in Java
We are going to discus about Object Class Methods in Java. The java.lang.Object class is the root of the class hierarchy tree in JDE(java development environment). Every Java class extends the java.lang.Object class directly
java - Java Beginners
core java therefore you should follow following hierarchy Servlets JSP Web...java   i have completed my core java.. and i want to learn advanced java what are the steps i should follow while learning advanced java
java - Java Beginners
the inheritance hierarchy and composition maps from the java class files...java  hi, what is jasper or jsafer? can u give me full details with example thanks   Hi friend, Jasper is a program to read Java
Create Subpackages (i.e. A Package inside another package)
inside an another package. The packages that comes lower in the naming hierarchy... in the hierarchy i.e. the package that we are putting into another package is called...:\nisha>javac CallPackage.java C:\nisha>java CallPackage
java lab programs - Java Beginners
java lab programs  Develop with suitable hierarchy, classes for Point, Shape, Rectangle, Square, Circle, Ellipse, Triangle, Polygon, etc. Design a simple test application to demonstrate dynamic polymorphism. 5. Design a Java
interface - Java Beginners
in java? what will achived using interface?  Hi friend, Interface... implementations from an interface. * The interface hierarchy is independent of the class hierarchy. * Capturing similarities between unrelated classes without
learning java
learning java  Am learning java. but i feel really confusing about the topics like objects and classes. some times the objects are referred as the instance of a class but when comes the hierarchy, there comes the topic like
Advertisements
 

 

 

DMCA.com