Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

IMPERIAL

IMPERIAL COLLEGE OF ENGINEERING


Affiliated by Rajshahi University college code: 385

Department of CSE

ASSIGNMENT ON: CSE 2142


B. Sc. Engg. Part-2, Odd Semester

SUBMISSION DATE: 08 DEC,2021


DDATE:09DDecember,2021

Assignment Name: polymorphism in java.

SUBMITTED BY:
MD: AMINUL HAQUE

ID: 1838520119
SUMITTED TO:
PART O2, ODD SEMESTER
IMRAN MUNNA
DEPAR
LECTURER, DEPT OF CSE
IMPERIAL COLLEGE OF ENGINEERING
TMENT OF CS
1
1. package polymorphism;

public class Person {

void print()
{
System.out.println("Name: Niloy");
}
}

package polymorphism;

public class Student extends Person{

int ID=1838520119;

@Override
void print()
{
System.out.println("Age:22");
System.out.println("Student ID:"+ID);
}
}

package polymorphism;

public class Test {

public static void main(String[] args) {

Person p = new Person();


p.print();

p = new Student();
p.print();

}
}

2
2. package overloading2;
class DispOvrload
{
public void show(char ch)
{
System.out.println ("Display: "+ch);
}
public void show(char ch, char ch1)
{
System.out.println("Display: "+ch+", and " + ch1);
}
}

package overloading2;
public class main {

public static void main (String args[] )


{
DispOvrload o1 = new DispOvrload();
o1.show('G');

3
o1.show( 'S', 'J' );
}
}

3.package overloding;

public class Multiply {

void mul() {
System.out.println("NULL");
}

void mul(int a, int b) {


System.out.println("Sum of two=" + (a * b));
}

void mul(int a, int b, int c) {


System.out.println("Sum of three=" + (a * b * c));
}

package overloding;

public class Polymorphism {

public static void main(String args[]) {


Multiply m = new Multiply();
4
m.mul();
m.mul(6, 10);
m.mul(10, 6, 5);

4.Overriding;

public class Person {


String name;
int age;
String college = "Imperial College";

void display( String n, int a)


{
n= name;
a= age;

void print()
{
System.out.println("College name: "+college);
}

5
package Overriding;

public class Student extends Person{


String result;
String University;

@Override
void print()
{
System.out.println("Student's Information: ");
System.out.println("Name: "+name);
System.out.println("Age: "+age);
System.out.println("Result: "+result);
System.out.println("College name: "+college);
System.out.println("University name: "+University);
}
}

package Overriding;

public class Test {


public static void main(String[] args) {
Student s= new Student();

s.name="Niloy";
s.age=22;
s.result = "A+";
s.University= "University of Rajshahi";
s.print();

}
}

You might also like