Você está na página 1de 14

Aim :Method Overloading Pratical No :-

class Sh
{
float area;
void area(int i)
{
area=i*i;
System.out.print("area is ="+area);
}
void area(int i,int j)
{
area=i*j;
System.out.print("area is="+area);
}
}
class R
{
public static void main(String args[])
{
Sh s1=new Sh();
s1.area(8);
Sh s2=new Sh();
s2.area(12,25);
}
}

System ID:2017009934
Aim :- Constructor Overloading Pratical No :-

class St
{
int rollno;
String name,city;
St()
{
rollno=1;
name="Sadiq";
city="Kashmir";
}
St(int a,String b,String c)
{
rollno=a;
name=b;
city=c;
}
void display()
{
System.out.println("roll no="+rollno);
System.out.println("name="+name);
System.out.println("city="+city);
}
}
class sh
{
public static void main(String args[])
{

System ID:2017009934
St s1=new St();
s1.display();
St s2=new St(36,"m=Rohit","Noida");
s2.display();
}
}

System ID:2017009934
Aim :- Practice sheet Constructors Pratical No -
class Pro
{
String a;
Pro()
{System.out.println("I love Programming languages");}
Pro(String i)
{a=i;
System.out.println("I love"+ a);}}
class Constructors
{
public static void main(String args[])
{
Pro p1=new Pro();
Pro p2=new Pro("Sadiq Khan");
}}

System ID:2017009934
Aim :- Pratice Sheet Contrcutors
Pratical No

class Rectangle
{
int length,breadth,area;
void method()
{
area=length*breadth;
System.out.println("the area ="+area);
}

Rectangle()
{
length=breadth=0;
}
Rectangle(int i,int j)
{
length=i;
breadth=j;
}
Rectangle(int i)
{
length=breadth=i;
}

}
class Area
{
public static void main(String args[])

System ID:2017009934
{
Rectangle a1=new Rectangle();

Rectangle a2=new Rectangle(2,4);


Rectangle a3=new Rectangle(4);
a1.method();
a2.method();
a3.method();
}
}

System ID:2017009934
Aim :- Pratice sheet Contructors Practical No :-
class AddAmount
{
int amount=65,i;
AddAmount()
{
System.out.println("no amount added,so the final amount=$"+amount);
}
AddAmount(int i)
{
amount=amount+i;
System.out.println("after adding $"+i+"the Final amount=$"+amount);}}
class Amount
{public static void main(String args[]){
AddAmount a1=new AddAmount();
AddAmount a2=new AddAmount(65);
AddAmount a3=new AddAmount(70);}}

System ID:2017009934
Aim :- Inheritance Overloading and Overriding
Practical No
import java.util.*;
class Sq
{
float i,j,k;
void area()
{
Scanner s1=new Scanner(System.in);
System.out.println("enter the length of Sq");
i=s1.nextFloat();
System.out.println("area of Sq is="+i*i);
}
}
class Rectangle extends Sq
{
void area(float a,float b)
{
i=a;
j=b;
k=i*j;
System.out.println("the area of rectangle ::::"+k);
}
}
class Rectinput extends Rectangle
{
void area()
{
Scanner s2=new Scanner(System.in);
System.out.println("enter the length and breadth of reactangle respectively");

System ID:2017009934
i=s2.nextFloat();
j=s2.nextFloat();
k=i*j;

System.out.println("the area of rectangle is="+k);


}
}
class Sadiqkhan
{
public static void main(String args[])
{
Rectangle r1=new Rectangle();
r1.area();
r1.area(4,5);
Rectinput z1=new Rectinput();
z1.area();
z1.area(8,9);}}

System ID:2017009934
Aim :- Use Of this Keyword Practical no

,class Student{
int rollno;
String name;
float fee;
Student(int rollno,String name,float fee){
this.rollno=rollno;
this.name=name;
this.fee=fee;
}
void display(){System.out.println(rollno+" "+name+" "+fee);}
}

class This{
public static void main(String args[]){
Student s1=new Student(111,"Rohit",5000f);
Student s2=new Student(112,"Amit",6000f);
s1.display();
s2.display();
}}

System ID:2017009934
Aim : -Use of Super Keyword
Practical No :-
class Person
{
void message()
{
System.out.println("This is person class");
}
}

class Student extends Person


{
void message()
{
System.out.println("This is student class");
}
void display()
{
message();

super.message();
}
}

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

System ID:2017009934
}
}

System ID:2017009934
Aim :- Use of Super()
Pratical No :-

class Person{
int id;
String name;
Person(int id,String name){
this.id=id;
this.name=name;
}
}
class Emp extends Person{
int salary;
Emp(int id,String name,int salary){
super(id,name);
this.salary=salary;
}
void display(){System.out.println(id+" "+name+" "+salary);}
}
class Super{
public static void main(String[] args){
Emp e1=new Emp(1,"Sadiq",5500);
e1.display();
}}

System ID:2017009934
System ID:2017009934

Você também pode gostar