Y
Y HA
Hi!
This code should output:
Run method overridden in Task class
overridden method run() in PeriodicTask class
but I'm having this :
# javac -version
javac 1.7.0_25
# javac CollectionTest.java
CollectionTest.java:18: error: incompatible types
@Override
^
required: Annotation
found: Override
CollectionTest.java:27: error: incompatible types
@Override
^
required: Annotation
found: Override
2 errors
/**
* Java program to demonstrate how to override method in Java.
* Overridden method are resolved during runtime based upon type of object
* @author Javin
*/
public class CollectionTest {
public static void main(String args[]) {
Runnable task = new Task();
task.run(); //call overridden method in Task
task = new PeriodicTask();
task.run(); //calls overridden method in PeriodicTas
}
}
class Task implements Runnable{
@Override
public void run() {
System.out.println("Run method overridden in Task class");
}
}
class PeriodicTask extends Task{
@Override
public void run() {
System.err.println("overridden method run() in PeriodicTask class");
}
}
This code should output:
Run method overridden in Task class
overridden method run() in PeriodicTask class
but I'm having this :
# javac -version
javac 1.7.0_25
# javac CollectionTest.java
CollectionTest.java:18: error: incompatible types
@Override
^
required: Annotation
found: Override
CollectionTest.java:27: error: incompatible types
@Override
^
required: Annotation
found: Override
2 errors
/**
* Java program to demonstrate how to override method in Java.
* Overridden method are resolved during runtime based upon type of object
* @author Javin
*/
public class CollectionTest {
public static void main(String args[]) {
Runnable task = new Task();
task.run(); //call overridden method in Task
task = new PeriodicTask();
task.run(); //calls overridden method in PeriodicTas
}
}
class Task implements Runnable{
@Override
public void run() {
System.out.println("Run method overridden in Task class");
}
}
class PeriodicTask extends Task{
@Override
public void run() {
System.err.println("overridden method run() in PeriodicTask class");
}
}