[SOLVED] SOLVED: Why does this code fail to compile in Java 7?

11.99 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

odt file icon Solution.odt (5.8 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
πŸ”’ Securely Powered by:
Secure Checkout
5/5 - (1 vote)

Scope and lifetime are distinct yet related issues in programming languages. Languages can sometimes make design decisions that cause a conflict between the scope and the lifetime of variables. Java’s decision to allow classes to be defined inside a method illustrates this conflict. Consider the following example: class AnonymousInnerClassInMethod { public static void main(String[] args) { int local = 1; Comparable compare = new Comparable () { public int compareTo(Object value) { return (Integer)value – local; } }; System.out.println(compare.compareTo(5)); } } Why does this code fail to compile in Java 7? Why does it compile in Java 8? What could it be modified so it would compile for Java 7?

  • Solution.odt