Hierarchy in java

Hierarchy in java

Design a vechicle class hierarchy in java?
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 : ADS
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 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 : ADS_TO_REPLACE_1 Constructor
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 : ADS_TO_REPLACE_1
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 : ADS_TO_REPLACE_1 Constructor Detail
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 : ADS
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
ModuleNotFoundError: No module named 'hierarchy'
ModuleNotFoundError: No module named 'hierarchy'  Hi, My Python... 'hierarchy' How to remove the ModuleNotFoundError: No module named 'hierarchy' error? Thanks   Hi, In your python environment you
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 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 : ADS
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 : ADS_TO_REPLACE_1
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 : ADS_TO_REPLACE_1
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
ModuleNotFoundError: No module named 'django-hierarchy'
ModuleNotFoundError: No module named 'django-hierarchy'  Hi, My... named 'django-hierarchy' How to remove the ModuleNotFoundError: No module named 'django-hierarchy' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'sqla-hierarchy'
ModuleNotFoundError: No module named 'sqla-hierarchy'  Hi, My... named 'sqla-hierarchy' How to remove the ModuleNotFoundError: No module named 'sqla-hierarchy' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'sqla-hierarchy'
ModuleNotFoundError: No module named 'sqla-hierarchy'  Hi, My... named 'sqla-hierarchy' How to remove the ModuleNotFoundError: No module named 'sqla-hierarchy' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-hierarchy'
ModuleNotFoundError: No module named 'django-hierarchy'  Hi, My... named 'django-hierarchy' How to remove the ModuleNotFoundError: No module named 'django-hierarchy' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'hierarchy-utils'
ModuleNotFoundError: No module named 'hierarchy-utils'  Hi, My... named 'hierarchy-utils' How to remove the ModuleNotFoundError: No module named 'hierarchy-utils' error? Thanks   Hi, In your python
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
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
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
ModuleNotFoundError: No module named 'odoo10-addon-mrp-production-hierarchy'
ModuleNotFoundError: No module named 'odoo10-addon-mrp-production-hierarchy...: ModuleNotFoundError: No module named 'odoo10-addon-mrp-production-hierarchy' How...-hierarchy' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'odoo10-addon-mrp-production-hierarchy'
ModuleNotFoundError: No module named 'odoo10-addon-mrp-production-hierarchy...: ModuleNotFoundError: No module named 'odoo10-addon-mrp-production-hierarchy' How...-hierarchy' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'odoo10-addon-mrp-production-hierarchy'
ModuleNotFoundError: No module named 'odoo10-addon-mrp-production-hierarchy...: ModuleNotFoundError: No module named 'odoo10-addon-mrp-production-hierarchy' How...-hierarchy' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'odoo10-addon-mrp-production-hierarchy'
ModuleNotFoundError: No module named 'odoo10-addon-mrp-production-hierarchy...: ModuleNotFoundError: No module named 'odoo10-addon-mrp-production-hierarchy' How...-hierarchy' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'odoo11-addon-maintenance-equipment-hierarchy'
-hierarchy'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'odoo11-addon-maintenance-equipment-hierarchy...-maintenance-equipment-hierarchy' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'odoo11-addon-maintenance-equipment-hierarchy'
-hierarchy'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'odoo11-addon-maintenance-equipment-hierarchy...-maintenance-equipment-hierarchy' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'odoo11-addon-maintenance-team-hierarchy'
ModuleNotFoundError: No module named 'odoo11-addon-maintenance-team-hierarchy...: ModuleNotFoundError: No module named 'odoo11-addon-maintenance-team-hierarchy' How...-team-hierarchy' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'odoo12-addon-maintenance-equipment-hierarchy'
-hierarchy'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'odoo12-addon-maintenance-equipment-hierarchy...-maintenance-equipment-hierarchy' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'odoo12-addon-maintenance-equipment-hierarchy'
-hierarchy'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'odoo12-addon-maintenance-equipment-hierarchy...-maintenance-equipment-hierarchy' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'odoo12-addon-maintenance-team-hierarchy'
ModuleNotFoundError: No module named 'odoo12-addon-maintenance-team-hierarchy...: ModuleNotFoundError: No module named 'odoo12-addon-maintenance-team-hierarchy' How...-team-hierarchy' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'odoo12-addon-maintenance-team-hierarchy'
ModuleNotFoundError: No module named 'odoo12-addon-maintenance-team-hierarchy...: ModuleNotFoundError: No module named 'odoo12-addon-maintenance-team-hierarchy' How...-team-hierarchy' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'odoo13-addon-maintenance-equipment-hierarchy'
-hierarchy'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'odoo13-addon-maintenance-equipment-hierarchy...-maintenance-equipment-hierarchy' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'django_view_hierarchy'
ModuleNotFoundError: No module named 'django_view_hierarchy'  Hi...: No module named 'django_view_hierarchy' How to remove the ModuleNotFoundError: No module named 'django_view_hierarchy' error? Thanks   Hi
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
ModuleNotFoundError: No module named 'django-admin-lightweight-date-hierarchy'
ModuleNotFoundError: No module named 'django-admin-lightweight-date-hierarchy...: ModuleNotFoundError: No module named 'django-admin-lightweight-date-hierarchy' How...-date-hierarchy' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'odoo10-addon-partner-multi-relation-hierarchy'
-hierarchy'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'odoo10-addon-partner-multi-relation-hierarchy...-partner-multi-relation-hierarchy' error? Thanks   Hi
ModuleNotFoundError: No module named 'odoo10-addon-partner-multi-relation-hierarchy'
-hierarchy'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'odoo10-addon-partner-multi-relation-hierarchy...-partner-multi-relation-hierarchy' error? Thanks   Hi
ModuleNotFoundError: No module named 'odoo10-addon-partner-multi-relation-hierarchy'
-hierarchy'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'odoo10-addon-partner-multi-relation-hierarchy...-partner-multi-relation-hierarchy' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-admin-lightweight-date-hierarchy'
ModuleNotFoundError: No module named 'django-admin-lightweight-date-hierarchy...: ModuleNotFoundError: No module named 'django-admin-lightweight-date-hierarchy' How...-date-hierarchy' error? Thanks   Hi, In your python
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. ADS
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
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>java CallPackage This is the function of the class HelloWorld

Ads