#62 Inner Class in Java
Вставка
- Опубліковано 23 січ 2025
- Check out our courses:
Java Full Stack and Spring AI - go.telusko.com...
Coupon: TELUSKO10 (10% Discount)
DevOps with AWS: From Basics to Mastery : go.telusko.com...
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : go.telusko.com...
Coupon: TELUSKO20 (20% Discount)
For More Queries WhatsApp or Call on : +919008963671
website : courses.telusk...
In this lecture we will learn:
What is an inner class in Java?
Static inner classes in Java
Advantages Of inner class
#1
Inner Class:-
We can also create a class inside another class.
class A
{
class B
{
}
}
You can call the method of class B by using the dot operator in between both classes A and B.
A.B obj= new B();
A dollar sign will be introduced in a class name that has an inner class indicating two different classes.
A$B. class
You also need to create an object of the outer class, to call the methods of an inner class.
#2
Static Inner Class:-
An inner class can also be declared as static.
When an inner class is declared as static, then you do not need to create an object for it.
But an outer class can not be made static.
#3
Advantage of inner class:-
Nested classes represent a particular type of relationship that is it can access all the members of the outer class, including private.
Nested classes make the code more readable and maintainable.
It makes the code more optimize.
Github repo : github.com/nav...
Java:- bit.ly/JavaUde...
Spring:- bit.ly/SpringU...
More Learning :
Java :- bit.ly/3x6rr0N
Python :- bit.ly/3GRc7JX
Django :- bit.ly/3MmoJK6
JavaScript :- bit.ly/3tiAlHo
Node JS :- bit.ly/3GT4liq
Rest Api :-bit.ly/3MjhZwt
Servlet :- bit.ly/3Q7eA7k
Spring Framework :- bit.ly/3xi7buh
Design Patterns in Java :- bit.ly/3MocXiq
Docker :- bit.ly/3xjWzLA
Blockchain Tutorial :- bit.ly/3NSbOkc
Corda Tutorial:- bit.ly/3thbUKa
Hyperledger Fabric :- bit.ly/38RZCRB
NoSQL Tutorial :- bit.ly/3aJpRuc
Mysql Tutorial :- bit.ly/3thpr4L
Data Structures using Java :- bit.ly/3MuJa7S
Git Tutorial :- bit.ly/3NXyCPu
Donation:
PayPal Id : navinreddy20
www.telusko.com
inner class in java are of four different types:
Non - Static inner class
Static inner class - It can access only static members of outer class
Anonymous inner class - inner class without any name , it is used to create only one object of inner class
Local inner class - inner class defined in method or block within inner class ( it can only access local variables of the method in which it is defined and local variables must be effectively final)
Bro is the best teacher in the world !
khan sir ka name suna ha
Only inner class can be static
And private
Good explaination
really good
Sir, please can u do videos in telugu?
Your explanation is wonderful. If u do videos in telugu, a lot of telugu people will understand and learn Java
bro 💕
Thanks
Thanks
sir when i am doing so i am getting error obj package not found
A obj = new A();
A.B = new obj.B();
//i have made class A and B as you made
//when i make B static it works well
To instantiate an inner class, you need to first create an instance of the outer class, then use that instance to create the inner class object.
A obj = new A();
A.B obj1 = obj.new B();
but sir ham to static ka object banaty hi nahi hy to ye kese ho raha hy
Why outer class cannot be private are protected
Are all inner class static and vice versa
" Why" the concept of Inner class?
Can someone please explain
I don't understand why you need innerclass