POLYMORPHISM

package com.cnc;

class Movie {
private String name;
public Movie(String name) {
this.name = name;
}
public String script() {
return "The plot is here";
}

public String getName() {
return name;
}
}
class Jollywood extends Movie{
public Jollywood() {
super("Assamese");
}
public String script() {
return "jai aai Axom";
}

}
class JatinBora extends Jollywood {
public JatinBora(){
}
public String script() {
return "ratnakar";
}
}
class Bollywood extends Movie {
public Bollywood() {
super("Hindi");
}
public String script(){
return "Jai hind!";
}
}
class Sharukh extends Bollywood {
public Sharukh(){
}
public String script() {
return "hehe";
}
}
public class Main {

public static void main(String[] args) {
for(int i=1; i<11;i++){
Movie movie = randomMovie();
System.out.println("MOVIE = "+ i+" i "+ movie.getName());
}
}
public static Movie randomMovie(){
int randomNum = (int)(Math.random()*5)+1;
System.out.println("RANDOM NUMER GENERATED WAS "+ randomNum);
switch (randomNum){
case 1:
return new Sharukh();
case 2:
return new JatinBora();
case 3:
return new Bollywood();
case 4:
return new Jollywood();
default:
return null;
}
}
}
RANDOM NUMER GENERATED WAS 2
MOVIE = 1 i Assamese
RANDOM NUMER GENERATED WAS 4
MOVIE = 2 i Assamese
RANDOM NUMER GENERATED WAS 1
MOVIE = 3 i Hindi
RANDOM NUMER GENERATED WAS 4
MOVIE = 4 i Assamese
RANDOM NUMER GENERATED WAS 3
MOVIE = 5 i Hindi
RANDOM NUMER GENERATED WAS 5

Popular posts from this blog

NUMBER PALINDROME CHALLENGE

ENCAPSULATION CHALLENGE

USER INPUT PRINT ORIGINAL,REVERSE ARRAY AND SORTED ARRAY