core java-day7
polymorpyism
static polymorphism/ compile time
if the method call is resolved in compile time called
compile time polymorphism
which method to be call is known at compile time
method overloading
over loading static method is called compile time polymorphism
or static polymorphism
public static void sort(String[] sub)
{
public static void sort(int[] num)
{
main()
{
sort(sub)
sort(num)
}
dynamic polymorphism/ runtime polymorphism
which method will be called know at run time
inheritance
super class and sub call having same method name
same parameter
class vehicle
{
public void run();
class car extends vehicle
{
public void run()
{
syso("car is running")
}
class bike extends vehicle
{
public void run()
{
}
main()
{
Vehile v;
v= new Car()
v.run();
v = new Bike()
v.run()
--------------------------------------------------------
super class reference can hold sub class object
byte
sort
int
long
float
int a = 10;
float b = a;
float b = 10.5f
int a = (int)b
------------------------------------------------------------------------
Abstraction
what is abstraction
abstraction is process of hiding the implementation showing only the functionality
to the user
two ways to achive abstraction
abstract class
if class has abstract keywod and one or more abstract method is called
1) abstract class can have abstract method and non abstract method
2) you cannot create object of abstract class
3) it ment for inheritance
3) which ever class is extending ,should provide the implementation for the
abstract method
0 to 90%
interface
100%
1) interface contain only obstract method
2) ment for inheritance
3) which is class is inheriting will provide the implementation for
abstract method
4) object of interface cannot be created
interface msoffice
{
open()
new()
saveas()
}
----------------------------------------------------------------------
java application
interface connection
{
public abstract connect()
class mysql implements connection
connect(){ logic to connect to java }
mongodb implements connection
connect(){ logic to connect to mogodb}
Oracle implements connection
connect(){ logic to connect to Oracle}
----------------------------------------------------------------------
interface list
{
void add()
void remove()
}
class linkedlist implements list
{
void add()
{
}
void remove()
{
class Arraylist implements list
{
void add()
{
}
void remove()
{
}
main()
{
linkedlist ll = new linkedlist()
ll.add()
Arraylist al = new Arraylist()
al.add()
stack s = new stack()
s.add()
}
test
{
Mysql o = new Mysql()
o.connect();
}
----------------------------------------------------------------------
part III
packages