Question

In: Computer Science

There are two kinds of interface polymorphism. Explain each with the use of Java snippets to...

There are two kinds of interface polymorphism. Explain each with the use of Java snippets to show polymorphic behavior. (Your code doesn't have to implement any algorithmic logic, just the essential set up needed to support your explanation.)

Solutions

Expert Solution

Static polymorphism

public class StaticPolymorphism {
        public static int sum(int a,int b) {
                return a+b;
        }
        public static int sum(int a,int b,int c) {
                return a+b+c;
        }
        public static void main(String[] args) {
                System.out.println(sum(10,20));
                System.out.println(sum(10,20,25));
                
        }
}

Dynamic polymorphism

interface Shape{
   double area();
}
class Circle implements Shape{
   private double radius;

   public Circle(double aRadius) {
       super();
       radius = aRadius;
   }

   @Override
   public double area() {
       return Math.PI * radius * radius;
   }
  
}
public class DynamicPolymorphism {
   public static void main(String[] args) {
       Shape s = new Circle(10);
       System.out.println(s.area());
   }
}

NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.

I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME


Related Solutions

This is for a java program. Payroll System Using Inheritance and Polymorphism 1. Implement an interface...
This is for a java program. Payroll System Using Inheritance and Polymorphism 1. Implement an interface called EmployeeInfo with the following constant variables: FACULTY_MONTHLY_SALARY = 6000.00 STAFF_MONTHLY_HOURS_WORKED = 160 2. Implement an abstract class Employee with the following requirements: Attributes last name (String) first name (String) ID number (String) Sex - M or F Birth date - Use the Calendar Java class to create a date object Default argument constructor and argument constructors. Public methods toString - returning a string...
Write a simple short Java program of your choice which illustrates inheritance, polymorphism and the use...
Write a simple short Java program of your choice which illustrates inheritance, polymorphism and the use of interfaces. The program should not take up more than half a page of size A4.
Use the below info to create a java program A GUI interface to ensure a user...
Use the below info to create a java program A GUI interface to ensure a user is old enough to play a game. Properly formatted prompts to input name, address, phone number, and age. Remember that name, address, phone number, etc. can be broken out in additional fields. Refer to the tutorial from this week’s Reading Assignment Multiple vs. Single Field Capture for Phone Number Form Input for help with this. Instructions to ensure that the information is displayed back...
There are two kinds of white dwarf stars. For each kind, explain the type of object...
There are two kinds of white dwarf stars. For each kind, explain the type of object it comes from and what it is made of, and how it is formed.
In Java Create an interface Create an interface Printing, which have a method getPageNumber () that...
In Java Create an interface Create an interface Printing, which have a method getPageNumber () that return page number of any printing. Create an abstract class named Novel that implements Printing. Include a String field for the novel's title and a double field for the novel price. Within the class, include a constructor that requires the novel title, and add two get methods--one that returns the title and one that returns the price. Include an abstract method named setPrice().. Create...
Inheritance - Polymorphism One advantage of using subclasses is the ability to use polymorphism. The idea...
Inheritance - Polymorphism One advantage of using subclasses is the ability to use polymorphism. The idea behind polymorphism is that several different types of objects can have the same methods, and be treated in the same way. For example, have a look at the code we’ve included for this problem. We’ve defined Shape as an abstract base class. It doesn’t provide any functionality by itself, but it does supply an interface (in the form of .area() and .vertices() methods) which...
Finish the following java question: Consider the following interface: interface Duty { public String getDuty(); }...
Finish the following java question: Consider the following interface: interface Duty { public String getDuty(); } Write a class called Student which implements Duty. Class Student adds 1 data field, id, and 2 methods, getId and setId, along with a 1-argument constructor. The duty of a Student is to study 40 hours a week. Write a class called Professor which implements Duty. Class Professor adds 1 data field, name, and 2 methods, getName and setName, along with a 1-argument constructor....
For each of the following Visual Basic code snippets, identify the syntax error.   If intX >...
For each of the following Visual Basic code snippets, identify the syntax error.   If intX > 100   lblResult.Text = "Invalid Data" End If   Dim str As String = "Hello" Dim intLength As Integer intLength = Length(str) If intZ < 10 Then   lblResult.Text = "Invalid Data"   Dim str As String = "123" If str.IsNumeric Then   lblResult.Text = "It is a number." End If   Select Case intX   Case < 0     lblResult.Text = "Value too low."   Case > 100     lblResult.Text = "Value too high."   Case Else     lblResult.Text = "Value...
Java OVERVIEW This program primarily focuses on the implementation of a ArrayList type interface and the...
Java OVERVIEW This program primarily focuses on the implementation of a ArrayList type interface and the necessary methods to implement the ArrayList. It also includes polymorphism and class comparison. INSTRUCTIONS Your deliverable will be to turn in three files. The files will be named Card.java, PremiumCard.java and the last file will be called CardArrayList.java. For this assignment, any use of a data control structure other than a simple Arrary or String will result in no credit. I am aware that...
Question1 if possible, could anyone do with explanation For each of the following code snippets, give...
Question1 if possible, could anyone do with explanation For each of the following code snippets, give both of the following: a. Give the overall T(n) run me analysis expression for the code. b. Describe the worst case running me of the code snippet in Big‑Oh notation. 1.for (int i=0;i<n;i++) { for (int j=0;j<n/2;j++) { sum++;} } 2.void silly(int n,int x,int y) { for (int i=0;i<n/2;i++) { if (x<y) { for (int j=0;j<100*n*n;j++) { cout<< "j="<<j<<endl;}} else {cout <<"i="<<i<<endl;}}} 3.void silly(int...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT