Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Question, From a C++ Programmer

Tags:

java

object

class

I'm learning Java, and now that I'm over the packages hump, things are going smoothly. I can draw similarities between most things I'm learning with things I already know at least the concept of. But what on earth is going on with the following bit of code? Is it some form of constructor, or anonymous object?

Something obj = new Something()
{
  private static final int num = 3;

  public void meth()
  {
    // w/e
  }
};
like image 812
Josh Avatar asked May 11 '26 09:05

Josh


1 Answers

You got it - this creates an anonymous inner class of Something.

See also: Nested Classes (The Java Tutorial) and Anonymous Classes.

like image 71
Matt Ball Avatar answered May 12 '26 23:05

Matt Ball



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!