java - How do I override a parent class's method? -
import java.io*; import java.awt.*; import java.util.concurrent.*; public class studentqueue<e> extends arrayblockingqueue<e> { public studentqueue(int capacity) { super(capacity); } }
how override corresponding parent class's methods? need override methods in java library arrayblockingqueue. how go implementing own method , having override method in parent class?
any example do, not have arrayblockingqueue. please , thank you.
if method has same name parent's, parameters , return type, you're overriding it. can add @override
annotation on top of method.
always check parent's method not final nor private.
for instance
public class parent{ public void method(string param){ //do stuff } private void notextendable(string param){ } protected void alsoextendable(string param){ } } public class subclass extends parent{ @override public void method(string param){ //super.method() //if want execute parent's method //do own stuff } }
you have information need here: http://docs.oracle.com/javase/tutorial/java/iandi/override.html
Comments
Post a Comment