Exp-2 Internet Programming

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Experiment 2

Student Name: Roshan Kumar UID: 20BCA1177


Branch: BCA Section/Group:3/A
Semester: 4 Date of Performance:21/02/2022
Subject Name: Internet Programing
Subject Code: 22E-20CAP-255

1. Aim/Overview of the practical:


I. Write a program of Method Overloading by Creating a class named 'PrintNumber'
to print various numbers of different data types by creating different methods with
the same name 'printn' having a parameter for each data type.
II. Create a class to print the area of a square and a rectangle. The class has two
methods with the same name but different number of parameters. The method for
printing area of rectangle has two parameters which are length and breadth
respectively while the other method for printing area of square has one parameter
which is side of square.

2. Steps involved
I. Create a class called ‘PrimeNumber’
Create different methods that will return various datatypes of numbers such as int,
float, double, short
The methods will have same name printn but different parameters
Create your main method
Give the corresponding values
Then compile using javac
Get the output
II. Create a class
Give two methods with same name but different parameters list
Create your main method
Print the output
FLOWCHART

Task-1

Task-2
3. Code for experiment/practical:

1.
class PrintNumber{
public int printn(int a){ // method overloading
return a;
}
public int printn(double b){ // same name function with different
parameters
return b;
}

public int printn(float c){


return c;
}

public int printn(long d){


return d;
}

public int printn(short x){


return x;
}
public int printn(byte y){ //return value of data type byte
return y;
]
}
Public class Number{
Public static void main(String[]args){
PrintNumber n=new PrintNumber();
System.out.println(“First number is: “ +n.print(6));
System.out.println(“Second number is: “ +n.print(24.82d));
System.out.println(“Third number is: “ +n.print(6.03f);
System.out.println(“Fourth number is: “ +n.print(294960284L));
System.out.println(“Fifth number is: “ +n.print(8076));
}
}

ii)
class AreaShape{ //first Method
public int area (int side){
return(side*side);}
public int area (int length, int breadth){ //Second method with same name
return(length*breadth);
}
}
Public class Areas{
Public static void main(String[]args){ //main method
AreaShape a=new AreaShape();
System.out.println(“The Area of Square is: “ +n.area(6));
System.out.println(“The Area of Rectangle is: “ +n.areat(2,8));
}
}
4. Result/Output/Writing Summary:

1
2)

Learning outcomes (What I have learnt):


a) Method Overloading means a class can have different methods with same
name, though arguments lists is different.
b) There are 3 ways of Overloading a method:
Number of parameters
data Type of parameters
Sequence of data type of parameters
c) Use of classes
d) Create multiple methods with the same name functions

Evaluation Grid:

Sr. No. Parameters Marks Obtained Maximum Marks


1. Demonstration and Performance 5
2. Worksheet 10
3. Post Lab Quiz 5

You might also like