Skip to main content
added 8 characters in body
Source Link
Sumit Singh
  • 16k
  • 6
  • 64
  • 90

I think, the convention that is generally followed is this:

  • static class within a top level class is a nested class
  • non static class within a top level class is a inner class, which further has two more form:
  • local class - named classes declared inside of a block like a method or constructor body
  • anonymous class - unnamed classes whose instances are created in expressions and statements

However, few other points to remembers are:

  • Top level classes and static nested class are semantically same except that in case of static nested class it can make static reference to private static fields/methods of its Outer [parent] class and vice versa.

  • Inner classes have access to instance variables of the enclosing instance of the Outer [parent] class. However, not all inner classes have enclosing instances, for example inner classes in static contexts, like an anonymous class used in a static initializer block, do not.

  • Anonymous class by default extends the parent class or implements the parent interface and there is no further clause to extend any other class or implement any more interfaces. So,

  • new YourClass(){};new YourClass(){}; means class [Anonymous] extends YourClass {} class [Anonymous] extends YourClass {}

  • new YourInterface(){};new YourInterface(){}; means class [Anonymous] implements YourInterface {} class [Anonymous] implements YourInterface {}


I feel that the bigger question that remains open which one to use and when? Well that mostly depends on what scenario you are dealing with but reading the reply given by @jrudolph may help you making some decision.

I think, the convention that is generally followed is this:

  • static class within a top level class is a nested class
  • non static class within a top level class is a inner class, which further has two more form:
  • local class - named classes declared inside of a block like a method or constructor body
  • anonymous class - unnamed classes whose instances are created in expressions and statements

However, few other points to remembers are:

  • Top level classes and static nested class are semantically same except that in case of static nested class it can make static reference to private static fields/methods of its Outer [parent] class and vice versa.

  • Inner classes have access to instance variables of the enclosing instance of the Outer [parent] class. However, not all inner classes have enclosing instances, for example inner classes in static contexts, like an anonymous class used in a static initializer block, do not.

  • Anonymous class by default extends the parent class or implements the parent interface and there is no further clause to extend any other class or implement any more interfaces. So,

  • new YourClass(){}; means class [Anonymous] extends YourClass {}

  • new YourInterface(){}; means class [Anonymous] implements YourInterface {}


I feel that the bigger question that remains open which one to use and when? Well that mostly depends on what scenario you are dealing with but reading the reply given by @jrudolph may help you making some decision.

I think, the convention that is generally followed is this:

  • static class within a top level class is a nested class
  • non static class within a top level class is a inner class, which further has two more form:
  • local class - named classes declared inside of a block like a method or constructor body
  • anonymous class - unnamed classes whose instances are created in expressions and statements

However, few other points to remembers are:

  • Top level classes and static nested class are semantically same except that in case of static nested class it can make static reference to private static fields/methods of its Outer [parent] class and vice versa.

  • Inner classes have access to instance variables of the enclosing instance of the Outer [parent] class. However, not all inner classes have enclosing instances, for example inner classes in static contexts, like an anonymous class used in a static initializer block, do not.

  • Anonymous class by default extends the parent class or implements the parent interface and there is no further clause to extend any other class or implement any more interfaces. So,

  • new YourClass(){}; means class [Anonymous] extends YourClass {}

  • new YourInterface(){}; means class [Anonymous] implements YourInterface {}


I feel that the bigger question that remains open which one to use and when? Well that mostly depends on what scenario you are dealing with but reading the reply given by @jrudolph may help you making some decision.

reorganized the statements and some more useful info
Source Link
sactiw
  • 22.6k
  • 4
  • 44
  • 28

The convention I think, the convention that is generally followed is this:

  • static classstatic class within a top level class is is a nested classnested class
  • non static classnon static class within a top level class class is a inner classinner class, which further has two more form:
  • local classlocal class - named classes declared inside of a block like a method or constructor body
  • anonymous classanonymous class - unnamed classes whose instances are created in expressions and statements

However, few other points to rememberspoints to remembers are:

  • Top level classes and static nested class are semantically same except that in case of static nested class it can make static referncereference to private static fields/methods of its Outer [parent] class and vice versa.

  • Inner classes have access to instance variables of the enclosing instance of the Outer [parent] class. However, not all inner classes have enclosing instances, for example inner classes in static contexts, like an anonymous class used in a static initializer block, do not.

  • Anonymous class by default extends the parent class or implements the parent interface and there is no further clause to extend any other class or implement any more interfaces. So,

  • new YourClass(){}; means class [Anonymous] extends YourClass {}

  • new YourInterface(){}; means class [Anonymous] implements YourInterface {}

 

I feel that the bigger question that always remains there isopen which one to use and when? Well that mostly depends on what scenario you are dealing with but reading one of the reply given above by "jrudolph" will certainly@jrudolph may help you making some decision.

The convention I think generally followed is this:

  • static class within a top level class is a nested class
  • non static class within a top level class is a inner class, which further has two more form:
  • local class
  • anonymous class

However, few other points to remembers are:

  • Top level classes and static nested class are semantically same except that in case of static nested class it can make static refernce to private static fields/methods of its Outer [parent] class and vice versa.

  • anonymous class by default extends the parent class or implements the parent interface and there is no further clause to extend any other class or implement any more interfaces. So,

  • new YourClass(){}; means class [Anonymous] extends YourClass {}

  • new YourInterface(){}; means class [Anonymous] implements YourInterface {}

I feel that the bigger question that always remains there is which one to use and when? Well that mostly depends on what scenario you are dealing with but reading one of the reply given above by "jrudolph" will certainly help you making some decision.

I think, the convention that is generally followed is this:

  • static class within a top level class is a nested class
  • non static class within a top level class is a inner class, which further has two more form:
  • local class - named classes declared inside of a block like a method or constructor body
  • anonymous class - unnamed classes whose instances are created in expressions and statements

However, few other points to remembers are:

  • Top level classes and static nested class are semantically same except that in case of static nested class it can make static reference to private static fields/methods of its Outer [parent] class and vice versa.

  • Inner classes have access to instance variables of the enclosing instance of the Outer [parent] class. However, not all inner classes have enclosing instances, for example inner classes in static contexts, like an anonymous class used in a static initializer block, do not.

  • Anonymous class by default extends the parent class or implements the parent interface and there is no further clause to extend any other class or implement any more interfaces. So,

  • new YourClass(){}; means class [Anonymous] extends YourClass {}

  • new YourInterface(){}; means class [Anonymous] implements YourInterface {}

 

I feel that the bigger question that remains open which one to use and when? Well that mostly depends on what scenario you are dealing with but reading the reply given by @jrudolph may help you making some decision.

reframing the sentence so that they make better sense to readers.
Source Link
sactiw
  • 22.6k
  • 4
  • 44
  • 28

WhatThe convention I followthink generally followed is this:

  • static class within a top level class is a nested class
  • non static class within a top level class is a inner class, which further has two more form:
  • local class
  • anonymous class

FewHowever, few other points to remembers are:

  • Top level classes and static nested class are semantically same except that in case of static nested class it can make static refernce to private static fields/methods of its Outer [parent] class and vice versa.

  • anonymous class by default extends the parent class or implements the parent interface and there is no further clause to extend any other class or implement any more interfaces. So,

  • new YourClass(){}; means class means class [Anonymous] extends YourClass {}

  • new YourInterface(){}; means class means class [Anonymous] implements YourInterface {}

TheI feel that the bigger question that always remains there is which one to use and when and? Well that mostly depends on what scenario you are dealing with but reading one of the reply given above by "jrudolph" will certainly help you making asome decision.

What I follow is this:

  • static class within a top level class is a nested class
  • non static class within a top level class is a inner class, which further has two more form:
  • local class
  • anonymous class

Few other points to remembers are:

  • Top level classes and static nested class are semantically same except that in case of static nested class it can make static refernce to private static fields/methods of its Outer [parent] class and vice versa.

  • anonymous class by default extends the parent class or implements the parent interface and there is no further clause to extend any other class or implement any more interfaces. So,

  • new YourClass(){}; means class [Anonymous] extends YourClass {}

  • new YourInterface(){}; means class [Anonymous] implements YourInterface {}

The bigger question remains is which one to use and when and depends on what scenario you are dealing with but reading one of the reply given above by "jrudolph" will certainly help you making a decision.

The convention I think generally followed is this:

  • static class within a top level class is a nested class
  • non static class within a top level class is a inner class, which further has two more form:
  • local class
  • anonymous class

However, few other points to remembers are:

  • Top level classes and static nested class are semantically same except that in case of static nested class it can make static refernce to private static fields/methods of its Outer [parent] class and vice versa.

  • anonymous class by default extends the parent class or implements the parent interface and there is no further clause to extend any other class or implement any more interfaces. So,

  • new YourClass(){}; means class [Anonymous] extends YourClass {}

  • new YourInterface(){}; means class [Anonymous] implements YourInterface {}

I feel that the bigger question that always remains there is which one to use and when? Well that mostly depends on what scenario you are dealing with but reading one of the reply given above by "jrudolph" will certainly help you making some decision.

Source Link
sactiw
  • 22.6k
  • 4
  • 44
  • 28
Loading