how OOPS concept playing roles in terms of compile time and run time polymorphism.

how inheritance and encapsulation and polymorphism applied in real time application.

when and where and how to decide this oop concept fit for this like java bean,interface,abstract,etc?

Recommended Answers

All 2 Replies

There are two types of polymorphism
1. compile time polymorphism
2. run time polymorphism.

Compile time polymorphism is functions and operators overloading.
Runtime time polymorphism is done using inheritance and virtual functions.[Eg: function overriding]

Compile time polymorphism is as new_programmer said, method and operator overloading.
Run time polymorphism is I think program to Interface over implementation. Following example will help to clear the idea -

Interface Shape {
    void draw();
}

class Circle implements Shape {
    void draw() {
        System.out.printlbn("Drawing circle");
    }
}
class Square implements Shape {
    void draw() {
        System.out.printlbn("Drawing square");
    }
}
Class testInter {
    public static void main(String [] args) {
        Shape s;
        s = new Circle();
        s.draw(); //Calling the draw method in circle
        s = new Square();
        s.draw(); //Calling the draw method in square
        // Method of which class will be invoked determined at runtime based on the 
        //reference variable.
    }
}

There are two types of polymorphism
1. compile time polymorphism
2. run time polymorphism.

Compile time polymorphism is functions and operators overloading.
Runtime time polymorphism is done using inheritance and virtual functions.[Eg: function overriding]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.