Search code examples
javaclassinheritancequeuepriority-queue

Inheriting properties of a class to another class


I created a class named Queue, which has some operations like insert, delete, search..etc.

Now I need to create another class named PriorityQueue that inherits properties of Queue class. The new PriorityQueue class also needs a special property named priority.

How could I do it?


Solution

  • Just extend your Queue class and add the attribute

    public class PriorityQueue extends Queue {
        private final String priority; //assuming it's a string 
        public PriorityQueue(String priority) {
            super(); //call parent constructor 
            this.priority = priority;
        }
    }