contructoroverloading
constructoroverloading
/** * @author arun * */ class Triangle { int b,h; float x,y; public Triangle(int x,int y) { b = x; h = y; } public int first() { return(b * h/2); } public Triangle(int a,double c) { b = a; h = b; } public int second() { return(b * h/2); } public Triangle(float c,float d) { x = c; y = d; } public float third() { return(x * y/2); } public Triangle(float e) { x = e; y = e; } public float fourth() { return(x * y/2); } } public class constoverload { public static void main(String[] args) { Triangle t1 = new Triangle(2,4); System.out.println("area in first triangle :" +t1.first()); Triangle t2 = new Triangle(6,8); System.out.println("area in second triangle :" +t2.second()); Triangle t3 = new Triangle(2.3945748484f,5.46374644f); System.out.println("area in third triangle :" +t3.third()); Triangle t4 = new Triangle(2.5555555864864f); System.out.println("area in fourth triangle :" +t4.fourth()); } } /* output area in first triangle :4 area in second triangle :24 area in third triangle :6.541675 area in fourth triangle :3.2654321 */
Please send comments to
vgdarur.javafive@blogger.com
Copyright © 2008 - iForeRunner.com
http://www.iforerunner.com/