java sample program

java sample program

hai
i need a sample program for polymorphism
View Answers

May 18, 2010 at 4:00 PM

Hi Friend,

Try the following code:

class Shape {
int x,y;
void area(){
}
}
class Square extends Shape {
int l=2;
void area() {
System.out.println(l*l);
}
}
class Rectangle extends Shape {
int l=2,b=3;
void area() {
System.out.println(l*b);
}
}
class Circle extends Shape {
int radius=5;
void area() {
System.out.println(3.14*radius*radius);
}
}
class Polymorphism {
public static void main(String[] args) {
Shape shapes[] = new Shape[4];
shapes[0]= new Shape();
shapes[1] = new Square();
shapes[2] = new Rectangle();
shapes[3] = new Circle();

for(int i=0;i<shapes.length;i++) {
shapes[i].area();
}
}
}

For more information, visit the following link:

http://www.roseindia.net/java/javascript-array/modified-java-method-overriding.shtml
http://www.roseindia.net/java/master-java/method_overloading.shtml
http://www.roseindia.net/answers/viewanswers/215.html

Thanks









Related Tutorials/Questions & Answers:
Sample java program
Sample java program  I want a sample program: to produce summary information on sales report. The program will input Data of Salesman Id, Item code, and number of cuestomer. Sales id is 5digit long, and items code range from
java sample program - Java Beginners
java sample program  hai i need a sample program for polymorphism  Hi Friend, Try the following code: class Shape { int x,y; void area(){ } } class Square extends Shape { int l=2; void area
Advertisements
sample Applet program
sample Applet program  I need Source Code for sample Applet program.   Hi Friend, Please visit the following link: Applet Tutorials Thanks
Sample program of JSP
Sample program of JSP  <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org
Axis2 sample program
Axis2 sample program  Hi.. I have tried the HelloWorldServie example... for the service: C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\axis2\WEB-INF...: The services.xml file cannot be found for the service: C:\Program Files\Apache Software
Sample program of JSP
Input program in JSP  <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org
Sample Java program for beginners
Here beginners in Java can learn to create there first Hello World program..., a programmer is ready to create their own Java program. Here we have also described.... After a program is created it must be converted by Java compiler and file
sample jsp-servlet-service-db program
sample jsp-servlet-service-db program  <%@ page language="java...; <%@ page language="java" contentType="text/html; charset...; <%@ page language="java" contentType="text/html; charset=ISO-8859-1
Getting Exception on UseDefinedException sample program - Please help me how to resolve
Getting Exception on UseDefinedException sample program - Please help me how to resolve  class UseDefinedException extends Exception{ String msg = ""; int marks; public UseDefinedException() ){ } public
Collection of Large Number of Java Sample Programs and Tutorials
Collection of Large Number of Java Sample Programs and Tutorials Java Collection Examples Java 6.0 New Features (Collection Framework...; HelloWorld Java Program Simple Java Program
java program for
java program for   java program for printing documents,images and cards
a Java program
a Java program    Write a Java program to print even numbers from 2 to 1024? Write a Java program to print ? My Name is Mirza? 100 times? Write a Java program to print Fibonacci Series? Write a Java program to reverse a number
Java Program
Java Program  A Java Program that print the data on the printer but buttons not to be printed
java program
java program  write a program to print 1234 567 89 10
java program
java program  Write a program to demonstrate the concept of various possible exceptions arising in a Java Program and the ways to handle them.  ... in Java
java program
java program  write java program for constructor,overriding,overriding,exception handling
Java Program
Java Program  java program to insert row in excel sheet after identifying an object
java program
java program  java program to implement the reflection of a particular class details like constructor,methods and fields with its modifiers
java program
java program  Write a program to create an applet and display The message "welcome to java
java program
java program  how to write an addition program in java without using arithematic operator
java program
java program  write a java program to display array list and calculate the average of given array
java program
java program  write a java program to display array list and calculate the average of given array
java program
java program  Write a java program to do matrix addition operation On two given matrices
java program
java program  Write a java program to find the number of Positive numbers in m* n matrix
java program
java program  hi friends how to make a java program for getting non prime odd numbers in a given series
java program
java program  write a java script program that would input the ff:Student Name,Average,Tuition Fee and output Total Tuition Fee. Formula: Total... 10% 84 and below no discount Sample Output: Student Name:_ Average:_ Tuition Fee
java program
java program  write a java script program that would input the ff... and below no discount   write a java script program that would...% 84 and below no discount   write a java script program
java program
java program   Write a program to find the difference between sum of the squares and the square of the sums of n numbers
java program
java program  write a program to create text area and display the various mouse handling events
java program
java program  Develop the program calculatePipeArea. It computes the surface area of a pipe, which is an open cylinder. The program accpets three values: the pipes inner radius, its length, and the thickness of its wall
java program
java program  . Develop the program calculatePipeArea. It computes the surface area of a pipe, which is an open cylinder. The program accpets three values: the pipes inner radius, its length, and the thickness of its wall
java program
java program  . Write a program which performs to raise a number to a power and returns the value. Provide a behavior to the program so as to accept any type of numeric values and returns the results
Java program
Java program  Write a program which performs to raise a number to a power and returns the value. Provide a behavior to the program so as to accept any type of numeric values and returns the results
program in java
program in java  write a reverse program in java using string buffer.the input and out put as follows. input- hi good mornig out put-ih doog ginrom
java program
java program  write a java program to compute area of a circle.square,rectangle.triangle,volume of a sphere ,cylinder and perimeter of cube using method over riding
java program
java program  write a java program to compute area of a circle.square,rectangle.triangle,volume of a sphere ,cylinder and perimeter of cube using method over riding
java program
java program   A B C D E F F E D C B A A B C D E E D C B A A B C D D C B A A B C C B A A B B A A A java program to display above triangle
java program
java program  write a program to create server and client such that server receives data from client using BuuferedReader and sends reply to client using PrintStream
java program
java program  write a program to read 10 numbers from user and store it in a array. display the maximum n minimum number in the array
java program
java program  Problem 1 Write a javaScript program that would input Employee Name, rate per hour, No. of hours worked and will compute the daily wage... worked plus OT pay Sample Output: Employee Name:__ Rate per hour:__ No.of
java program
java program  write a java program to read a file which hold email address validate email address tohave formate @.* and replace all .com email address
java program
java program  write a java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array
java program
java program  write a java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array
java program
java program  write a java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array
Java Program
Java Program  I want to Write a program in JAVA to display to create a class called MATRIX using a two-dimensional array of integers. Perform the addition and subtraction of two matrices. Help me
java program
java program  i want a applet program that accepts two input strings using tag and concatenate the strings and display it in status window. please give mi he code for this in core java
java program
java program  i want a applet program that accepts two input strings using tag and concatenate the strings and display it in status window. please give mi he code for this in core java
java program
java program  i want a applet program that accepts two input strings using tag and concatenate the strings and display it in status window. please give mi he code for this in core java
java program
java program  Write a program that computes loan payments. The loan can be a car loan, a student loan, or a home mortgage loan. The program lets the user enter the interest rate, number of years, loan amount, and displays
java program
java program  . Develop a program that computes the distance a boat travels across a river, given the width of the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time

Ads