(Method Overlaoding) : System ID:2017010200

You might also like

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

(METHOD OVERLAODING)

class Shape
{
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 Run
{
public static void main(String args[])
{
Shape s1=new Shape();
s1.area(6);
Shape s2=new Shape();
s2.area(15,25);
}}

System ID:2017010200
System ID:2017010200
CONSTRUCTOR OVERLOADING
class Student
{
int rollno;
String name,city;
Student()
{
rollno=1;
name="Zayanto";
city="New Delhi";
}
Student(int a,String b,String c)
{
rollno=a;
name=b;
city=c;

System ID:2017010200
}
void display()
{
System.out.println("roll no="+rollno);
System.out.println("name="+name);
System.out.println("city="+city);
}
}
class Show
{
public static void main(String args[])
{

Student s1=new Student();


s1.display();
Student s2=new Student(36,"mohit","Noida");
s2.display();
}}

System ID:2017010200
PRACTICE SHEET(CONSTRUCTORS)
class Programming
{

System ID:2017010200
String a;
Programming()
{System.out.println("I love programming languages");}
Programming(String i)
{a=i;
System.out.println("I love"+ a);}}
class Constructors
{
public static void main(String args[])
{
Programming p1=new Programming();
Programming p2=new Programming("Zayanto");
}}

System ID:2017010200
PRACTICE SHEET(CONSTRUCTORS)
class Rectangle
{
int length,breadth,area;
void method()
{
area=length*breadth;
System.out.println("the area ="+area);
}

Rectangle()
{
length=breadth=0;

System ID:2017010200
}
Rectangle(int i,int j)
{
length=i;
breadth=j;
}
Rectangle(int i)
{
length=breadth=i;
}

}
class Area
{
public static void main(String args[])
{
Rectangle a1=new Rectangle();

Rectangle a2=new Rectangle(2,4);


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

System ID:2017010200
}

System ID:2017010200
PRACTICE SHEET(CONSTRUCTORS)
class AddAmount
{
int amount=50,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(55);
AddAmount a3=new AddAmount(70);}}

System ID:2017010200
System ID:2017010200
INHERITANCE,OVERLOADING AND OVERRIDING
import java.util.*;
class Square
{
float i,j,k;
void area()
{
Scanner s1=new Scanner(System.in);
System.out.println("enter the length of square");
i=s1.nextFloat();
System.out.println("area of square is="+i*i);
}
}
class Rectangle extends Square
{
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

System ID:2017010200
{
void area()
{
Scanner s2=new Scanner(System.in);
System.out.println("enter the length and breadth of reactangle
respectively");
i=s2.nextFloat();
j=s2.nextFloat();
k=i*j;

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


}
}
class Zayanto
{
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:2017010200
Use of This Keyword
class Student{
int rollno;

System ID:2017010200
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,"mohit",5000f);
Student s2=new Student(112,"sumit",6000f);
s1.display();
s2.display();
}}

System ID:2017010200
System ID:2017010200
Use of Super Keyword
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 Sh
{
public static void main(String args[])

System ID:2017010200
{
Student s = new Student();
s.display();
}
}

System ID:2017010200
Use of Super()
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 Super1{
public static void main(String[] args){
Emp e1=new Emp(1,"mohit",5500);
e1.display();
}}

System ID:2017010200
System ID:2017010200

You might also like