Day 7: Java Notes
Day 7: Java Notes
Polymorphism:
=============
Executing methods in more than one from.
poly-> many
Morphism -> form
Two Type:
Method overloading - compile time polymorphism/ static binding/static polymorphism
Method overriding - runtime polymorphism/dynamic binding/dynamic polymorphism.
Method Overloading:
Same method name
Same class
Different argument
Number of argument :
Int
Int, float
Float, string, char
Boolean, int, long, string
Data Types :
Int
Float
String
char
Boolean
Long
Order of argument:
String, long
Float, string
Int, boolean
Method Overriding:
Same method name
Different class
Same arguments
Over Loading Program:
—-----------
package org.poly;
public class EmployeeDetails {
//based on the number of argument
public void empDetail(int empid) {
System.out.println("employee ID is"+ empid);
}
public void empDetail(String empname, int empage) {
System.out.println("employee name is "+ empname);
System.out.println("employee age is "+empage);
}
// based on the data type
public void empDetail(long phno) {
System.out.println("employee phone number is "+ phno);
}
public void empDetail(String add) {
System.out.println("employee address is "+ add);
}
// based on the order of argument
public void empDetails(float empPreSal, String emppreComp) {
System.out.println("employee previous salary is "+ empPreSal);
System.out.println("employee previous company is "+ emppreComp);
}
public void empDetail(String empCurrentComp, float empcurrentSal) {
System.out.println("employee current company is "+ empCurrentComp);
System.out.println("employee current salary is "+ empcurrentSal);
}
public static void main(String[] args) {
EmployeeDetails emp= new EmployeeDetails();
emp.empDetail(102);
emp.empDetail("jeba", 24);
emp.empDetail(6758493028l);
emp.empDetail("chennai");
emp.empDetails(10000.10f, "HCL");
emp.empDetail("wipro", 15000.24f);
}
}
—----------------------------------------------------------------
Overriding:
—-------------
package org.poly;
public class RBI {
public void savings() {
System.out.println("5%");
}
public void fixed() {
System.out.println("2%");
}
public static void main(String[] args) {
}}
—------------------------------------------------------------------------
package org.poly;
public class SBI extends RBI{
@Override
public void savings() {
// TODO Auto-generated method stub
System.out.println("2%");
}
@Override
public void fixed() {
// TODO Auto-generated method stub
System.out.println("1%");
}
public static void main(String[] args) {
SBI s=new SBI();
s.savings();
s.fixed();
}
}
Assessment :
—-----------------
Question 1:
—---------------
Project :CompanyDetails
Package :org.company
Class :CompanyInfo
Methods :companyName()
Description
You have to overload the method companyName() based on different Number of arguments.
Overriding Program:
—--------------------------------
package org.poly;
public class RBI {
public void savings() {
System.out.println("5%");
}
public void fixed() {
System.out.println("2%");
}
public static void main(String[] args) {
}}
package org.poly;
public class SBI extends RBI{
@Override
public void savings() {
// TODO Auto-generated method stub
System.out.println("2%");
}
@Override
public void fixed() {
// TODO Auto-generated method stub
System.out.println("1%");
}
public static void main(String[] args) {
SBI s=new SBI();
s.savings();
s.fixed();
}
}
Assignment :
QUESTION 1:
------------
Project :BankDetails
Package :org.bank
Class :BankInfo
Methods :saving(),fixed(),deposit()
Class :AxisBank
Methods :deposit()
Description:
You have to override the method deposit in AxisBank.
Comments
Post a Comment