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

Given the following list of classes, attributes and methods, - identify which it

ID: 3670603 • Letter: G

Question

Given the following list of classes, attributes and methods,

- identify which items are classes, which items are attributes and which items are methods;

- identify which class each attribute and method belongs to; and

- suggest a class hierarchy given your list of classes.

*Note - no particular capitalization scheme is used in the list below to differentiate between classes, methods and attributes.

Brew, DecreaseTemperature, Manufacturer, MinCups, Price, TurnOff, Oven, MaxTemperature, BrewStrength, NumberOfRacks, IncreaseTemperature, TurnOn, StartTimer, CoffeeMaker, KitchenAppliance, MaxCups, YearBuilt, Grind

2. What is an abstract class? What is an interface? How are abstract classes and Interfaces the same? How are they different? Finally, how do you use abstract methods defined inside an abstract class or Interface?

Explanation / Answer

2)

>Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods
Here's an example:

abstract public class AbstractClass
{
abstract public void abstractMethod();
public void implementedMethod()
{
System.out.print("implementedMethod()");
}
final public void finalMethod()
{
System.out.print("finalMethod()");
}
}

>Interface looks like class but it is not a class. An interface can have methods and variables just like the class but the methods declared in interface are by default abstract (only method signature, no body). Also, the variables declared in an interface are public, static & final by default.

>Abstract class and interface both are used to achieve abstraction where we can declare the abstract methods. Abstract class and interface both can't be instantiated.

Abstract class:
>Abstract class can have abstract and non-abstract methods.
>Abstract class doesn't support multiple inheritance.
> Abstract class can have final, non-final, static and non-static variables
>The abstract keyword is used to declare abstract class.
>Example:
public abstract class Shape
{
public abstract void draw();
}

Interface
>Interface can have only abstract methods.
>Interface supports multiple inheritance.
>Interface can't have static methods, main method or constructor.
>The interface keyword is used to declare interface.
>Example:
public interface Drawable
{
void draw();
}


>Abstract methods are usually declared where two or more subclasses are expected to do a similar thing in different ways through different implementations. These subclasses extend the same Abstract class and provide different implementations for the abstract methods.
>Abstract classes are used to define generic types of behaviors at the top of an object-oriented programming class hierarchy, and use its subclasses to provide implementation details of the abstract class

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