Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

C Books Guide and List
C++ Books Guide and List
Best Java Books

0 votes
93 views
asked by (24.6k points) 29 53 85

1 Answer

0 votes
yes, The local inner class may have constructor.
 
interface Counter {
  int next();
}

public class MainClass{
 
  private int count = 0;
  Counter getCounter(final String name) {
    // A local inner class:
    class LocalCounter implements Counter {
      public LocalCounter() {
        // Local inner class can have a constructor
        System.out.println("LocalCounter()");
      }
      public int next() {
        System.out.print(name); // Access local final
        return count++;
      }
    }
    return new LocalCounter();
  }
 
  public static void main(String[] args) {
    MainClass lic = new MainClass();
    Counter c1 = lic.getCounter("Local inner ");
  }
}
answered by (15k points) 16 23 30

Related questions

0 votes
1 answer 18 views
0 votes
1 answer 18 views
18 views asked by john (27.1k points) 31 51 100
0 votes
1 answer 33 views
33 views asked by john (27.1k points) 31 51 100
+1 vote
1 answer 57 views
0 votes
1 answer 40 views
40 views asked by john (27.1k points) 31 51 100
...