Java File
Java File
Program of exception handling by try and catch block . Program to show multiple catch block . Program to show nested try . Program to throw an exception by throw statement . Program to create your own exception .
23 30 45
twoD[i][j]=k; k++; } System.out.println(The TWO D Array is); for(int i=0;i<4;i++) { for(int j=0;j<4;j++) { System.out.print(twoD*i+*j++ ); } System .out.print(); } } }
Output:
The TWO D Array is 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
f1.length=7.5; f1.height=8.0; f1.width=6.0; double vol; vol=f1.length*f1.height*f1.width; system.out.println(value of F1=+vol); f2.length=9.6; f2.height=6.7; f2.width=8.5; vol=f2.length*f2.height*f2.width; system.out.println(value of F2=+vol); } } Output: Value of F1=360.0 Value of F2=546.71999999
{ System.out.println(k=+k); } void sum() { System.out.println(sum of I,j and k=+(i+j+k)); } } class inherit { public static void main(string args[]) { A a=new A(); a.i=10; a.j=20; system.out.println(content of object a are=); a.show_ij(); B.b= new B(); b.i=30; b.j=40; b.k=50; system.out.println(content of object b are=); b.show_ij(); b.show_k(); b.sum(); } }
Output: Content of a object a are= i=10 j=20 content of object b are = i=30 j=40
} void test(double d) { System.out.println(Value of double D=+d); } } class old { public static void main(string args[]) { oload ol=new oload(); ol.test(); ol.test(70); ol.test(16,39); ol.test(19.753); } } Output:
No Arguments Value of A=70 Value of A=16 and B=39 Value of double D=19.753
} box4(box4 ob) { length=ob.length; height=ob.height; width=ob.width; } double vol() { double vol=length*height*width; return vol; } } class bd { public static void main(string args[]) { box4 b1=new box4(8.75,6.73,9.1); box4 b2=new box4(8.53); box4 b3=new box4(b1); system.out.println(Value of B1=+b1.vol()); system.out.println(value of B2="()) system.out.println(value of b3=+b3.vol()); } } Output: Value of B1=535.87625 Value of B2=620.6504769999999 Value of B3=535.87625
{ int c; beta1(int I,int j,int k) { super(I,j); c=k; } void show() { super.show(); system.out.println(k=+c); } } class overidn { public static void main(string args[]) { beta1 b=new beta1(5,10,15); b.show(); } } Output: I=5 and j=10 K=15
public static void main(string args[]) { a ab=new a(); ab.display(); } } Output: Class A of First Package
public double compute(double x, double y) { return(x*y); } } class itf { public static void main(string args[]) { circle c=new circle(); rectangle r= new rectangle(); system.out.println(Circle=+c.compute(5,5)); system.out.println(Rectangle=+r.compute(6,8)); } } Output: Circle=78.5 Rectangle=48.0
} y=a/(b+c); system.out.println(Y=+y); } }
} catch(ArrayIndexOutOfBoundsException e) { System.out.println(Array index out of Bound); } catch(ArrayStoreException e) { System.out.println(Wrong Data type); } z=a[1]/a[0]; system.out.println(Z=+z); } } Output: Array index out of Bound Z=2
c=b/(b-5); system.out.println(C=+c); } if(a==2) { int x[]={1,2}; system.out.println(X*2+=+x*2+); } System.out.println(End of Inner Try); } catch(ArrayIndexOutOfBoundsException e) { System.out.println(Array Index Out Of Bound); } d=a+b; system.out.println(D=+d); system.out.println(End of Outer Try ); } catch(ArithmeticException e) { System .out.println(Division By Zero ); } System.out.println(End ); } } Output : This is Outer Try Start of Inner Try End of Inner try D=5 End of Outer Try End
{ z=a/b; if(z<.001) { throw new mexp(Number is too small); } else { System.out.println(Z=+z); } } catch(mexp e) { System.out.println(My exception caught); System.out.println(End ); } } } Output:
My exception caught END