covariant type in java
class A {}
class B extends A {}
class Base {
A fun() {
System.out.println("Base fun()");
return new A();
}
}
class Derived extends Base {
B fun() {
System.out.println("Derived fun()");
return new B();
}
}
public class Main {
public static void main(String args[]) {
Base base = new Base();
base.fun();
Derived derived = new Derived();
derived.fun();
}
}
Also in Java:
- Primitive Type vs. Reference Type
- isSelfDivisor java
- declare bufferedreader java
- how to minimize jframe in java
- how to open a webpage with java
- java arraylist
- java store hexadecimal value
- java console text color
- how to print to the console in java
- list java oracle
- funzione random in java
- close scanner java
- money value commas java
- how to play an audio in java
- sqrt in java
- countdown timer with seekbar
- creating a program about user asked to enter a number and enters 0 to stop, then calculates the sum of numbers entered, the average, the length of positive numbers and negative numbers entered by the user in java
- java int stream min
- hashset contains java
- query java persistence
- how to create a button in java
- convert every character in string to arraylist jva
- java list get first element
- even or odd in java