java sample program

Ads

 
 
 

Share on Google+Share on Google+

shareen
java sample program
1 Answer(s)      7 years ago
Posted in : Java Beginners
hai
i need a sample program for polymorphism
Ads
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

Ads









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 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... of the special class. Java First Example-Hello World: Now we will create our first program
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
java sample code - Java Beginners
java sample code  hai...... i need a full sample program fo inheritance.........  Hi Friend, Please visit the following link: http://www.roseindia.net/java/language/inheritance.shtml Thanks
Sample Code For ArrayLlist - Java Beginners
Sample Code For ArrayLlist   Hi Friend, I want sample... ArrayList.Give sample code for Arraylist with realtime application.  Hi I... about ArrayList. http://www.roseindia.net/java/example/java/util
Collection of Large Number of Java Sample Programs and Tutorials
Collection of Large Number of Java Sample Programs and Tutorials Java... example of java program is provided that shows you how you can...; HelloWorld Java Program Simple
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
Java sample using - for loop, if then else etc etc
Java sample using - for loop, if then else etc etc  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
Iterator Java Sample
Java Sample Iterator interface makes the traversing of the elements easy...() Java Sample Iterator Example import java.util.ArrayList; import... sample { public static void main(String[] args) { List list = new ArrayList
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
Looking for sample project in java using netbeans
Looking for sample project in java using netbeans  Hi all, i am novice in developing desktop application in java using netbeans. can anyone pls help...;Please visit the following link: http://www.roseindia.net/java/java-tips
need a sample project using java technologies like jsp, servlets, struts
need a sample project using java technologies like jsp, servlets, struts  Hi everybody! I have learnt core java,jdbc,jsp,servlets & struts. Please guide me where can i find sample project like library management, CMS or any
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
The Sample Banner Example in Java
Java - The Sample Banner Example in Java   ... the banner in java applet. Simply the banner is used to advertising for any.... In this program we will see how to display the banner in applet. This example has
sir, how to convert excel file to csv file using java? please send me sample code.
sir, how to convert excel file to csv file using java? please send me sample code.  please send me sample code for converting excel file into csv file uisng java
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 for
java program for   java program for printing documents,images and cards
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  (1) WAP in java to take input of int,string,float and print them (use scanner class)? Sample output- Enter an int : 10 Enter a string... of a circle and calculate area? formula=pirr (use math class) sample output
java program 1
java program 1  (4) WAP to take input of a String and check wheather it is valid number or not? Sample Output1: Enter a String : 10 10 is a number Sample Output2: Enter a String : 10b1 10b1 is not a number (5) WAP to take
Java Program
Java Program  A Java Program that print the data on the printer but buttons not to be printed
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
Ajax sample
Ajax sample  Hi, Where I can find the samples of Ajax program? Thanks   Hi, Please see Ajax Tutorials. Thanks
java program
java program  write a program to print 1234 567 89 10
Java Program
Java Program  Problem Statement You are required to write a program... given, then your program must create the expression: 8 - 5 * 2 = -2 Here... Sample Test Cases Test Case 1 Input: 4 8 5 2 -2 Output: -* Test Case 2 Input: 5
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 display array list and calculate the average of given array
Tutorials   
Java Spring Hibernate Struts Training ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java

Ads

 
Advertisement null

Ads