Categories: Java

Regular class vs static nested class

Comparison between a normal or regular class and a static nested class.

S.NONormal/Regular inner classStatic nested class
1.Without an outer class object existing, there cannot be an inner class object. That is, the inner class object is always associated with the outer class object.There may be a static nested class object if an outer class object does not exist. That is, the outer class object is not linked to the static nested class object.
2.Static members cannot be declared inside a normal/regular inner class.Static members can be declared inside a static nested class.
3.Regular inner classes cannot be invoked directly from the command prompt because the main() method cannot be declared.The static nested class can be invoked directly from the command prompt because the main() method can be declared.
4.Outer class members can be accessed directly, both static and non-static.A static member of the outer class is the only one that can be directly accessed.

Note: also read about the Nested Class in Java

Follow Me

If you like my post, please follow me to read my latest post on programming and technology.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Share
Published by
Rabecca Fatima

Recent Posts

Square Root of Integer

Given an integer A. Compute and return the square root of A. If A is…

1 year ago

Build Array From Permutation

Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…

1 year ago

DSA: Heap

A heap is a specialized tree-based data structure that satisfies the heap property. It is…

1 year ago

DSA: Trie

What is a Trie in DSA? A trie, often known as a prefix tree, is…

1 year ago

Trees: Lowest Common Ancestor

What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…

1 year ago

Binary Search Tree (BST)

A Binary Search Tree (BST) is a type of binary tree that satisfies the following…

1 year ago