Professional Documents
Culture Documents
Week3 1
Week3 1
Objective: After the completion of the practice session, the student will be able
toimplement OOP Second principle – Polymorphism.
a) Create overloaded methods to find volume of Sphere, Cylinder &
Cone.
/* Use Method overloading concept to solve the problem.
• Volume of Sphere: 4/3 p r3
• Volume of Cylinder: p r2h
• Volume of Cone: 1/3 p r2h */
Output:
b) To sort given list of elements in ascending order.
import java.util.*;
public class SortDemo
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
import java.util.*;
public class MatrixDemo
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of Matrix A - m * n");
int m = sc.nextInt();
int n = sc.nextInt();
System.out.println("Enter the size of Matrix B - p * q");
int p = sc.nextInt();
int q = sc.nextInt();
if (n != p)
{
System.out.println("Multiplication cannot be performed");
System.exit(0);
}
int a[][] = new int[m][n];
int b[][] = new int[p][q];
int c[][] = new int[m][q];
}
}
Output: