Ask Question
9 March, 20:06

Add the function min as an abstract function to the class arrayListType to return the smallest element of the list. Also, write the definition of the function min in the class unorderedArrayListType and write a program to test this function.

+4
Answers (1)
  1. 9 March, 20:39
    0
    The Answer is given in the explanation section, See detailed explanations as comments within the code.

    Explanation:

    import java. util. ArrayList;

    import java. util. Collections;

    import java. util. List;

    / / The abstract class with the abstract method

    public abstract class arrayListType {

    public abstract int smallestElement ();

    }

    //Class to implement the the abstract method

    class unorderedArrayListType{

    public int smallestElement () {

    //Create the list of Intitial capacity of 5

    List myList = new ArrayList (5);

    //Add Elements to the list

    myList. add (3);

    myList. add (4);

    myList. add (1);

    myList. add (6);

    myList. add (7);

    //FInd the smallest integer and return it

    int smallestInt = Collections. min (myList);

    return smallestInt;

    }

    }

    //Testing the class with a main method

    class Testing {

    public static void main (String[] args) {

    / / Creating an instance of the class unorderedArrayListType

    unorderedArrayListType list1 = new unorderedArrayListType ();

    //Calling the method to print the smallest Integer in the List

    System. out. println (list1. smallestElement ());

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Add the function min as an abstract function to the class arrayListType to return the smallest element of the list. Also, write the ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers