By saying <? extends Instrument>, we're saying, "I can be assigned a collection that is a subtype of List and typed for <Instrument> or anything that extends Instrument. And oh yes, I SWEAR that I will not ADD anything into the collection."
Program 1 :
----------
public class SCJP{
public static void main(String[] args) {
final int x = 10;
short y = x ;
System.out.print(x);
System.out.println(y);
}
}
Program 2 :
-----------
public class SCJP{
public static void main(String[] args) {
final int x;
x = 10;
short y = x ;
System.out.print(x);
System.out.println(y);
}
}
MyClass class1 = new MyClass(10);
Myclass class2 = new MyClass(20);
Myclass class3 = class1;
class1 = class2;
class2 = class3;
class MyClass{
void myMethod(){
final int x = 5;
System.out.println("Value of x in myMethod = " + x);
}
void mySecondMethod(){
System.out.println("Value of x outside myMethod = " + x);
}
}