Day 15 - 29 August, 2024

Program 37 : WAP to explain the implementation of interfaces and abstract classes

// First Meeting interface School { void registration(); void feeSubmission(); void batchAllotment(); } // Second Meeting abstract class Test1 implements School { public void registration() { System.out.println("Business Logic of registration"); } } // Third Meeting abstract class Test2 extends Test1 { public void feeSubmission() { System.out.println("Business Logic of Fee Submission"); } } // Fourth Meeting class Test3 extends Test2 { public void batchAllotment() { System.out.println("Business Logic of batch Allotment"); } } class P37 { public static void main(String[] args) { Test3 t = new Test3(); t.registration(); t.feeSubmission(); t.batchAllotment(); } } Copy Code
Expected Output:
Business Logic of registration
Business Logic of Fee Submission
Business Logic of batch Allotment

Program 38 : WAP to use the package created by yourself

package mypack; public class Calct { public int add(int x, int y) { return (x + y); } public int greatest(int x, int y) { return x > y ? x : y; } } Copy Code import java.util.Scanner; import mypack.Calct; class P38 { public static void main(String[] args) { int a, b, s, g; Scanner sc = new Scanner(System.in); Calct ob = new Calct(); System.out.println("----------------------"); System.out.print("Enter value of a : "); a = sc.nextInt(); System.out.print("Enter value of b : "); b = sc.nextInt(); System.out.println("----------------------"); s = ob.add(a, b); g = ob.greatest(a, b); System.out.println("the addition is : " + s); System.out.println("the greatest is : " + g); System.out.println("----------------------"); } } Copy Code
----------------------
Enter value of a : 5
Enter value of b : 3
----------------------
The addition is : 8
The greatest is : 5
----------------------