UrbanPro
true

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Java :: Inner Class Concepts

M
Marimuthu P.
13/12/2016 0 0

Java:: Inner Class Concepts
---------------------------------

Inner class concepts introduced in Java v1.1
- as a part of AWT Event Handling improvements.
When to use Inner class:
- Without existing One type of object, if there is no chance for existence of Another type of object then we should go for Inner Class.
Eg 1.
Collge and Department.
Department object can exists if and only if College object exists.

.....................................
public class College {

  class Department {

  }
}
.....................................

Eg 2.
Map and Entry in java.util Collections Framework.
Entry object is meaningless without Map object.

.....................................
public interface Map<K, V> {

    interface Entry<K, V> {

    }
}
.....................................

- Relation between Outer and Inner class is "Has-a" relationship OR
Composition OR Aggregation relationship.

Types of inner class:
There are 4 types based on the position of declaration and behaviour

4 types of Innerclass

1. Normal OR Regular Inner classes
2. Method local Inner classes
3. Anonymous Inner classes
4. Static nested classes.

Note:
* We can't touch inner classes directly.
* So, static members not allowed inside inner class.
* Inner classes can have static final CONSTANTS.

Type-1. Normal/Regular Inner class
~~~~~~~~~~~~~~~~~~~~~~
- Named class declared without static modifier directly inside class is called Normal Inner class.

class Outer {
   class Inner {

   }
}

// Outer.class
// Outer$Inner.class

Accessing InnerClass from
1. Instance area of Outer class
Inner z = new Inner(20).m1();

2. From Static area of Outer class
Outer z = new Outer();
Outer.Inner m = z.new Inner(10);

Outer.Inner n = new Outer().new Inner(40);

Note:
From Normal/Regular inner class we can access both static and non-static members of Outer class directly.
Nesting of Inner classes is possible.

Inner.this.a; // 200
Outer.this.a; // 100

Allowed Access Modifiers:
-----------------------------
for Outer class
public, friendly, final, abstract, strictfp

for Inner class
public, friendly, final,
abstract, strictfp +
private, protected and static.

0 Dislike
Follow 0

Please Enter a comment

Submit

Other Lessons for You

Java and C trainer
Always think any conspect with real-time example like Object -- object must have states and behaviour then only we will call that thing is Object like fan is Object (rotating,color)

Tips for Entry Level Java Job Seeker
3 steps you should take to make a break as a Java developer: Step 1: Invest in improving your job hunting skills encompassing interviewing, networking, and resume writing skills. Step 2: Keep applying...
A

Akshay Shende

1 0
0

Java : Command Line Arguments
The parameters which are provided to the program at the command line. Eg:d:\>java a 10 20 30 Here,“java” is an interpreter, “a” is filename,10,20,30 are arguments passed to...
S

Svg Reddy

0 0
0

Tips of learning Java Language/Other Programming Languages
1.You should know the basic concept: If we talk about programming languages so basic concept are same in all the high level languages. So you should know the basic concept firstly then you can easily understand...
I

ICreative Solution

0 0
0

Advance Java
1) Servlet • Basics of Servlet • Servlet Request • Servlet Collaboration • Servlet Config • Servlet Context • Attribute • Session Tracking • Event and Listener •...
A
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more