Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java dynamic method dispatch

package com.company;
class Phone{
    public void showTime(){
        System.out.println("Time is 8 am");
    }
    public void on(){
        System.out.println("Turning on Phone...");
    }
}

class SmartPhone extends Phone{
    public void music(){
        System.out.println("Playing music...");
    }
    public void on(){
        System.out.println("Turning on SmartPhone...");
    }
}
public class cwh_49_dynamic_method_dispatch {
    public static void main(String[] args) {
        // Phone obj = new Phone(); // Allowed
        // SmartPhone smobj = new SmartPhone(); // Allowed
        // obj.name();

        Phone obj = new SmartPhone(); // Yes it is allowed
        // SmartPhone obj2 = new Phone(); // Not allowed

        obj.showTime();
        obj.on();
        // obj.music(); Not Allowed


    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: print values of bst java 
Java :: method returns arraylist java 
Java :: java length of matrix 
Java :: printing 2d array in java 
Java :: java remove space at the end of string 
Java :: convert arraylist to array in java 
Java :: create new empty list java 
Java :: operador ternario java 
Java :: string programs in java 
Java :: timestamp to date java 
Java :: double.parsedouble in java 
Java :: pivot in array 
Java :: does finally block executed after crash 
Java :: java read next line 
Java :: number of digits java 
Java :: Java Insert Elements to HashSet 
Java :: converter float para string em java 
Java :: java convert array to list 
Java :: hashmap to list java 
Java :: javac clear 
Java :: hadoop-master error java_home is not set and could not be found 
Java :: string to int 
Java :: convert double into integer 
Java :: statusbar text color android 
Java :: java convert edittext to double 
Java :: loop hash map 
Java :: How to draw Bezier Curve in Android 
Java :: add two numbers bitwise 
Java :: how to give square in java 
Java :: java list select field 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =