0% found this document useful (0 votes)
47 views4 pages

Lab 5

The document contains code that: 1) Creates a package called p1 with classes one and two, with class one containing methods to add, multiply, divide numbers and a main method. 2) Creates another class usepack that extends class one and imports package p1, with a new method to get the modulus and calls other methods from class one. 3) Defines an interface I1 with two methods and a class sample that implements the interface with implementations for both methods. 4) Defines another interface I2 that extends I1 with two new methods, and a class sample that implements I2 and provides implementations for all four methods.

Uploaded by

Akanksha Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views4 pages

Lab 5

The document contains code that: 1) Creates a package called p1 with classes one and two, with class one containing methods to add, multiply, divide numbers and a main method. 2) Creates another class usepack that extends class one and imports package p1, with a new method to get the modulus and calls other methods from class one. 3) Defines an interface I1 with two methods and a class sample that implements the interface with implementations for both methods. 4) Defines another interface I2 that extends I1 with two new methods, and a class sample that implements I2 and provides implementations for all four methods.

Uploaded by

Akanksha Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Program:22 Date: 27-09-2012 Aim: Write an application that creates a package p1. Add some classes in it.

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(); } }

You might also like