0% found this document useful (0 votes)
1 views5 pages

Core Java Day7

The document discusses polymorphism in Java, distinguishing between static (compile-time) and dynamic (runtime) polymorphism, including method overloading and inheritance examples. It explains abstraction through abstract classes and interfaces, highlighting their characteristics and usage in Java applications. Additionally, it covers the implementation of interfaces by various classes, showcasing examples with database connections and data structures.

Uploaded by

darshandb941
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views5 pages

Core Java Day7

The document discusses polymorphism in Java, distinguishing between static (compile-time) and dynamic (runtime) polymorphism, including method overloading and inheritance examples. It explains abstraction through abstract classes and interfaces, highlighting their characteristics and usage in Java applications. Additionally, it covers the implementation of interfaces by various classes, showcasing examples with database connections and data structures.

Uploaded by

darshandb941
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

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

You might also like