[go: up one dir, main page]

0% found this document useful (0 votes)
25 views2 pages

j11 - Lab Task Two

The provided code defines a base class 'IPhone' and two subclasses 'IPhone14' and 'IPhone15' that override the 'displayFeatures' method to show specific features for each model. The 'Main' class creates instances of 'IPhone14' and 'IPhone15', calling their respective methods to display their features. This demonstrates polymorphism in object-oriented programming.

Uploaded by

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

j11 - Lab Task Two

The provided code defines a base class 'IPhone' and two subclasses 'IPhone14' and 'IPhone15' that override the 'displayFeatures' method to show specific features for each model. The 'Main' class creates instances of 'IPhone14' and 'IPhone15', calling their respective methods to display their features. This demonstrates polymorphism in object-oriented programming.

Uploaded by

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

1)

Code:
class IPhone {
public void displayFeatures() {
System.out.println("This is an iPhone with standard features");
}
}

class IPhone14 extends IPhone {


public void displayFeatures() {
System.out.println("iPhone 14 features: 6.1-inch display, A15 Bionic chip, Dual-camera system");
}
}

class IPhone15 extends IPhone {


public void displayFeatures() {
System.out.println("iPhone 15 features: 6.7-inch display, A16 Bionic chip, Triple-camera system");
}
}

class Main {
public static void main(String[] args) {
IPhone phone1 = new IPhone14();
IPhone phone2 = new IPhone15();

phone1.displayFeatures();
phone2.displayFeatures();
}
}
Output:

You might also like