Lab 5
Lab 5
package p1; public class one { public String str="hello"; public int add(int a,int b) { int x=a; int y=b; int sum=x+y; return sum; } int mul(int s,int t) { int x=s; int y=t; int product= s*t; return product; } int divide(int q,int p) { int x=q; int y=p; int qu=x/y; return qu; } public static void main(String[] args) { one o=new one(); int sum=o.add(2,6); System.out.println("sum="+sum); two t=new two(); t.print(); } } class two { public void print() { System.out.println("print:hello world"); } protected void show() { System.out.println("show:hello all"); }}
Program:23 Date: 27-09-2012 Aim: Write an application that uses package pi in a program. import p1.*; class usepack extends p1.one { int mod(int a,int b) { int x=a; int y=b; int z=a%b; return z; } public static void main(String[] args) { usepack p=new usepack(); int s=p.add(3,5); System.out.println("s="+s); System.out.println("string:"+p.str); } } OUTPUT:
Program:24 Date: 27-09-2012 Aim: Write an application that creates an interface and implements it. interface I1 { void print(); void lolz(); } class sample implements I1 { public void print() { System.out.println("OMG"); } public void lolz() { System.out.println("lolz"); } public static void main(String args[]) { sample s=new sample(); s.print(); s.lolz(); } } OUTPUT:
Program:25 Date: 27-09-2012 Aim: Write an application to illustrate Interface Inheritance interface I1 { void print(); void lolz(); } interface I2 extends I1 { void show(); void hehe(); } class sample implements I2 { public void print() { System.out.println("OMG"); } public void lolz() { System.out.println("lolz"); } public void show() { System.out.println("sea"); } public void hehe() { System.out.println("haha"); } public static void main(String args[]) { sample s=new sample(); s.print(); s.lolz(); s.hehe(); s.show(); } }