Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java question Write an abstract class that implements the following stack interf

ID: 3759751 • Letter: J

Question

Java question
Write an abstract class that implements the following stack interface
The abstract class should have an instance variable named 'size' It should have abstract methods for rush, pop and contains. The getCurrentSize method should return the size variable.
Interface simplestackinterface <T> { Void push(T item); T pop() Boolean contains (T item); Isn't getCurrentSize (); }
What's the difference between making size private or protected Java question
Write an abstract class that implements the following stack interface
The abstract class should have an instance variable named 'size' It should have abstract methods for rush, pop and contains. The getCurrentSize method should return the size variable.
Interface simplestackinterface <T> { Void push(T item); T pop() Boolean contains (T item); Isn't getCurrentSize (); }
What's the difference between making size private or protected
Write an abstract class that implements the following stack interface
The abstract class should have an instance variable named 'size' It should have abstract methods for rush, pop and contains. The getCurrentSize method should return the size variable.
Interface simplestackinterface <T> { Void push(T item); T pop() Boolean contains (T item); Isn't getCurrentSize (); }
What's the difference between making size private or protected The abstract class should have an instance variable named 'size' It should have abstract methods for rush, pop and contains. The getCurrentSize method should return the size variable.
Interface simplestackinterface <T> { Void push(T item); T pop() Boolean contains (T item); Isn't getCurrentSize (); }
What's the difference between making size private or protected

Explanation / Answer

Answer for above problem is below:

// Abstract class must contains all public abstract methods it may or may not contains methods definition
public abstract class Stack implements simplestackinterface{
public abstract void push(T item);
   public abstract T pop();
public abstract boolean contains(T item);
   public abstract int getCurrentSize();

   final private int size;
}

Protected :
If source was protected (so accessible by subclasses) then code gets messy:
who's changing the variables? When it's an object it then becomes hard when you need to refactor,
whereas a method tends to make this step easier.
If your getter/setter methods aren't getting and setting, then describe them as something else.

private:

An abstract class is a basis for different subclasses that share behaviour which does not need to
be repeatedly be created. Subclasses must complete the behaviour and have the option to override predefine
behaviour (as long as it is not defined as final or private)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote