Task - OOPS Concepts - Polymorphism - Polymorphic Reference #69
Replies: 51 comments 2 replies
public interface Notification {
void notifyUser();
}
public class SMSNotification implements Notification {
@Override
public void notifyUser() {
System.out.println("recieved sms");
}
}
public class EmaiNotify implements Notification {
@Override
public void notifyUser() {
System.out.println("recieved email"); }
}
public class NotificationDemo {
public static void main(String[] args) {
Notification notify_sms = new SMSNotification();
notify_sms.notifyUser();
notify_sms = new EmaiNotify();
notify_sms.notifyUser();
}
} |
interface Notification
{
void notifyUser();
}
class SMSNotification implements Notification{
@Override
public void notifyUser()
{
System.out.println("Sending an SMS notification");
}
}
class EmailNotification implements Notification
{
@Override
public void notifyUser()
{
System.out.println("Sending an e-mail notification");
}
}
public class PolymorphicReferenceDemo
{
public static void main(String[] args) {
Notification notification;
Notification ob1=new SMSNotification ();
ob1.notifyUser();
Notification ob2=new EmailNotification();
ob2.notifyUser();
}
} |
public interface Notification {
void notifyuser();
}
public class SMSNotification implements Notification {
@Override
public void notifyuser() {
System.out.println("Sending an SMS notification");
}
}
public class EmailNotification implements Notification{
@Override
public void notifyuser() {
System.out.println("Sending an e-mail notification");
}
}
``
public class Mainmethod {
public static void main(String[] args) {
Notification notification;
notification =new SMSNotification();
notification.notifyuser();
notification =new EmailNotification();
notification.notifyuser();
}
}
|
public interface Notification {
void notifyUser();
}
public class SMSNotification implements Notification {
@Override
public void notifyUser() {
System.out.println("Sending an SMS notification");
}
}
public class EmailNotification implements Notification {
@Override
public void notifyUser() {
System.out.println("Sending an e-mail notification");
}
}
public class PolymorphicReferenceDemo {
public static void main(String[] args) {
Notification notification1;
Notification notification2;
notification1=new SMSNotification();
notification2=new EmailNotification();
notification1.notifyUser();
notification2.notifyUser();
}
|
package com.simplilearn.task1.notification;
public interface Notification {
public void printNotification();
}
package com.simplilearn.task1.notification;
public class SMS implements Notification {
@Override
public void printNotification() {
// TODO Auto-generated method stub
System.out.println("Sending an SMS notifiaction");
}
}
package com.simplilearn.task1.notification;
public class Email implements Notification{
@Override
public void printNotification() {
// TODO Auto-generated method stub
System.out.println("Sending an Email Notification");
}
}
package com.simplilearn.task1.driver;
import com.simplilearn.task1.notification.Email;
import com.simplilearn.task1.notification.Notification;
public class MainNotification {
public static void main(String[] args) {
Notification notification;
notification=new Email();
notification.printNotification();
notification=new SMS();
notification.printNotification();
}
} |
|
public interface Notification { } public class SMSNotification implements Notification { } public class EmaiNotification implements Notification { } public class NotificationDemo { } |
package creational;
interface Notification{
void notifyUser();
}
class SMSNotification implements Notification{
public void notifyUser() {
System.out.println("SMS");
}
}
class EmailNotification implements Notification{
public void notifyUser() {
System.out.println("Email");
}
}
public class FactoryPattern {
public static void main(String[] args) {
// TODO Auto-generated method stub
Notification smsnotification = new SMSNotification();
smsnotification.notifyUser();
Notification emailnotification = new EmailNotification();
emailnotification.notifyUser();
}
}
|
public interface Notification
{
void notifyUser();
}
class SMSNotification implements Notification{
@Override
public void notifyUser() {
System.out.println("sending an SMS notification");
}
}
public class EmailNotification implements Notification {
@Override
public void notifyUser() {
System.out.println("sending an Email notification");
}
}
public class PolymorphicReferenceDemo {
public static void main(String[] args) {
Notification notification;
Notification ob1=new SMSNotification ();
ob1.notifyUser();
Notification ob2=new EmailNotification();
ob2.notifyUser();
}
} |
Solutioninterface Notification {
void notifyUser();
}
class SMSNotification implements Notification {
@Override
public void notifyUser() {
System.out.println("Sending an SMS notification");
}
}
class EmailNotification implements Notification {
@Override
public void notifyUser() {
System.out.println("Sending an e-mail notification");
}
}
public class PolymorphicReferences {
public static void main(String[] args) {
Notification notification; // Polymorphic Reference
notification = new SMSNotification();
notification.notifyUser();
notification = new EmailNotification();
notification.notifyUser();
}
} |
public interface Notification {
void notifyUser();
}
public class SMSNotification implements Notification {
@Override
public void notifyUser() {
// TODO Auto-generated method stub
System.out.println("Sending an SMS notification");
}
}
public class EmailNotification implements Notification {
@Override
public void notifyUser() {
// TODO Auto-generated method stub
System.out.println("Sending an e-mail notification");
}
}
public class PolymorphicReferenceDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Notification notification;
notification = new SMSNotification();
notification.notifyUser();
notification = new EmailNotification();
notification.notifyUser();
}
} |
interface Notification
{
void notifyUser();
}
class SMSNotification implements Notification{
@Override
public void notifyUser() {
// TODO Auto-generated method stub
System.out.println("Sending an sms Notifications");
}
}
class EmailNotification implements Notification{
@Override
public void notifyUser() {
// TODO Auto-generated method stub
System.out.println("Sending an email Notifications");
}
}
public class PolymorphicrRfences
{
public static void main(String[] args) {
Notification notification;
notification =new SMSNotification();
notification.notifyUser();
notification=new EmailNotification();
notification.notifyUser();
}
}
|
|
``Java public interface Notification { } package com.live; public class EmailNotification implements Notification { } public class SMSNotification implements Notification { } package com.live; public class PolymorphicReferenceDemo { } |
package com.oops.ply;
interface Notification {
void notifyUser();
}
class SMSNotification implements Notification{
@Override
public void notifyUser() {
System.out.println("Sending an sms notification");
}
}
class EmailNotification implements Notification
{ @Override
public void notifyUser() {
System.out.println("sending email notification");
}
}
public class PolymorphicReferernce {
public static void main(String[] args) {
Notification notification;
notification=new SMSNotification();
notification=new EmailNotification();
notification.notifyUser();
notification.notifyUser();
}
}
|
interface Notification
{
void notifyUser();
}
class SMSNotification implements Notification
{
@Override
public void notifyUser() {
System.out.println("Sending sms Notification");
}
}
class EmailNotification implements Notification
{
@Override
public void notifyUser() {
System.out.println("Sending an email Notification");
}
}
public class d69
{
public static void main(String[] args) {
Notification notification;
notification =new SMSNotification();
notification.notifyUser();
notification=new EmailNotification();
notification.notifyUser();
}
} |
public class D69
{
public static void main(String[] args)
{
Notification notification;
Notification obj1 = new smsNotification();
obj1.notifyUser();
Notification obj2 = new emailNotification();
obj2.notifyUser();
}
}
interface Notification
{
void notifyUser();
}
class smsNotification implements Notification
{
@Override
public void notifyUser()
{
System.out.println("Sending an SMS notification");
}
}
class emailNotification implements Notification {
@Override
public void notifyUser() {
System.out.println("Sending an e-mail notification");
}
} |
interface Notification {
void notifyUser();
}
class SMSNotification implements Notification {
@Override
public void notifyUser() {
System.out.println("Sending SMS Notification");
}
}
class EmailNotify implements Notification {
@Override
public void notifyUser() {
System.out.println("Sending an Email Notification");
}
}
public class PolymorphicReferenceDemo {
public static void main(String[] args) {
Notification notify_sms = new SMSNotification();
notify_sms.notifyUser();
notify_sms = new EmailNotify();
notify_sms.notifyUser();
}
} |
interface Notification {
void notifyUser();
}
class SMSNotification implements Notification {
@Override
public void notifyUser() {
System.out.println("Sending SMS Notification");
}
}
class EmailNotify implements Notification {
@Override
public void notifyUser() {
System.out.println("Sending an Email Notification");
}
}
public class PolymorphicReferenceDemo {
public static void main(String[] args) {
Notification notify_sms = new SMSNotification();
notify_sms.notifyUser();
notify_sms = new EmailNotify();
notify_sms.notifyUser();
}
} |
|
package com.training.microservice.assignment1; public interface Notification { package com.training.microservice.assignment1; public class EmailNotification implements Notification { public void notifyUser() { } package com.training.microservice.assignment1; public class SMSNotification implements Notification { public void notifyUser() { } package com.training.microservice.assignment1; /**
*/ } |
|
package edureka; public class EmailNotification implements Notification{ public class SMSNotification implements Notification{ } |
|
`package Edurekha; public interface Notification { public class SMSNotification implements Notification{ public class PolymorphicReferenceDemo { ` |
|
Hi @akash-coded, Please find below solution. My name sayan panja public class EdurecaTest { } |
|
interface Notification{ class SMSNotification implements Notification{ } |
|
interface Notification { class SMSNotification implements Notification { } class EmailNotification implements Notification { } class PolymorphicReferenceDemo { } |
|
``// Online Java Compiler interface Notification } class SMSNotification implements Notification{ } } class PolymorphicReferenceDemo } |
|
interface Notification() |
|
` } |
|
interface Notification{ notification =new EmailNotification(); |
|
interface Notification { public class SMSNotification implements Notification{ } public class EmailNotification implements Notification{ } public static class PolymorphicReferenceDemo{ } |
Uh oh!
There was an error while loading. Please reload this page.
Write a Java program to do the following.
Create an interface called
Notificationas follows:Implement the
Notificationinterface in two classes namedSMSNotificationandEmailNotification. Override the abstract method(s) of the interface in these concrete classes and print the messages"Sending an SMS notification"and"Sending an e-mail notification"respectively.Create a driver class called
PolymorphicReferenceDemo. The driver class will contain themain()method. Inside themain()method, define an object reference of typeNotificationas follows:Then, do the following:
SMSNotificationclass and assign it to thenotificationreference variable. Use the reference to call thenotifyUser()method.EmailNotificationclass and assign it to thenotificationreference variable. Use the reference to call thenotifyUser()method.All reactions