Question: write the method that takes an array of objects of type ClassA and a single object x of type ClassA as parameters. Code of ClassA

write the method that takes an array of objects of type ClassA and a single objectxof type ClassA as parameters. Code of ClassA is provided. The method returns the number of occurrences of object x in the given array of objects. When array is empty, the method returns 0.

import java.util.ArrayList;

public class ClassB {

private ArrayList first;

private int second;

public ClassB()

{

first = new ArrayList(1);

second = 0;

}

public ClassB(ClassB obj)

{

System.out.println("Placeholder for copy constructor");

}

public void push(String n)

{

first.add(n);

second++;

}

public String toString()

{

if (second == 0) return "{first=[]; second=0}";

else return "{first="+first.toString()+"; second="+second+"}";

}

public ArrayList getFirst()

{

return new ArrayList();

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!