hey everyone! I need help creating a program in java. I haveto illustrate inheri
ID: 3618406 • Letter: H
Question
hey everyone! I need help creating a program in java. I haveto illustrate inheritance but I don't really understand what thatis. My program has to have 2 abstract and concrete methods. Then Ineed an abstract class to override one of its methods of the class.It must also have its own properties. Furthermore, it needs threenon0inherited methods and one static method. It has to implementthe comparable interface and override the toString and equalmethods in the class. I'm so confused!! Please help me!! I don't understand what anyof this means and an example of it in code would really help! hey everyone! I need help creating a program in java. I haveto illustrate inheritance but I don't really understand what thatis. My program has to have 2 abstract and concrete methods. Then Ineed an abstract class to override one of its methods of the class.It must also have its own properties. Furthermore, it needs threenon0inherited methods and one static method. It has to implementthe comparable interface and override the toString and equalmethods in the class. I'm so confused!! Please help me!! I don't understand what anyof this means and an example of it in code would really help!Explanation / Answer
Inheritance is a designprinciple in object oriented languages like Java. Inheritance meansthat classes acquire methods and properties by declaring that theyare a sub-class of a class that already has those features. Thiscan significantly improve the efficiency and management of codebecause methods only need to be written once and can be used by anynumber of sub-classes. An abstract class is one that is designed toprovide methods or properties to sub-classes like a template.Abstract classes cannot be instantiated in their own right andusually contain abstract methods that sub-classes must implement tocomplete the intended inheritance program design. For instance,abstract methods may have a concrete method that calls an abstractmethod, whose implementation varies in each sub-class. Example: This is the Abstract Class public abstract class AbstractClass implements Comparable { public abstract void abstractMethod1(); public abstract void abstractMethod2(); public void ConcreteMethod() { } public void ConcreteMethod1() { } public int compareTo(Object obj) { return 0; } public String toString(Object obj) { return "TestString"; } public boolean equal(Object obj) { return true; } } Sub class created by inheritance public class ConcreteClass extends AbstractClass { public void abstractMethod1() { } public void abstractMethod2() { } } Helped?
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.