0% found this document useful (0 votes)
28 views

Abstract Class

This document defines an abstract vehicle class with a steer method and subclasses for bicycle and car that override the steer method. It also defines a familycar subclass of car that further overrides steer. The main method creates an array of vehicle objects, including a bicycle and familycar, and calls steer on each to output "Turn handle bars" and "This is my car" respectively.

Uploaded by

Karunakar Ella
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Abstract Class

This document defines an abstract vehicle class with a steer method and subclasses for bicycle and car that override the steer method. It also defines a familycar subclass of car that further overrides steer. The main method creates an array of vehicle objects, including a bicycle and familycar, and calls steer on each to output "Turn handle bars" and "This is my car" respectively.

Uploaded by

Karunakar Ella
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

ABSTRACT CLASS PROGRAM: import java.io.

*; abstract class vehicle { abstract void steer(); } class bicycle extends vehicle { void steer() { System.out.println("Turn handle bars"); } } abstract class car extends vehicle { void steer() { System.out.println("Turn steering wheel"); } } class familycar extends car { void steer() { System.out.println("This is my car"); } } class vehicles { public static void main(String[]args) { vehicle[] v={new bicycle(),new familycar()}; for(int i=0;i<v.length;i++) { v[i].steer(); } } }

OUTPUT: C:\Program Files\Java\jdk1.6.0_21\bin>javac vehicles.java C:\Program Files\Java\jdk1.6.0_21\bin>java vehicles Turn handle bars This is my car

You might also like