#46 Anonymous Object in java
Вставка
- Опубліковано 17 січ 2023
- Check out our courses:
Enterprise Java Spring Microservices: go.telusko.com/enterpriseJava
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : bit.ly/java-spring-cloud
Coupon: TELUSKO20 (20% Discount)
Udemy Courses:
Java:- bit.ly/JavaUdemyTelusko
Spring:- bit.ly/SpringUdemyTelusko
Java For Programmers:- bit.ly/javaProgrammers
For More Queries WhatsApp or Call on : +919008963671
website : courses.telusko.com/
In this lecture we will learn:
- Object creation in Java
- Anonymous objects in Java
- Difference between Simple objects and Anonymous objects
#1
In JVM, we have both stack memory and heap memory.
- Object is created in the heap memory that contains variable and methods, it also have some address.
- A obj=new A();
obj.show();
here, A is the classname.
obj refers to the address say 101
show() is a method that is called using reference variable obj.
- Every time you call an object, it will call the constructor as well.
- Object creation can be done in two ways:
1. Declare an object - creating a reference
2. Creating an object - and assigning the value to it
e,g., A obj;
obj=new A();
*new A() shows that you are creating an object.
- Reference of an object is created in the stack.
#2
Anonymous Objects:-
Anonymous objects are simply created by using the new keyword.
- It does not have any reference for an anonymous object.
e.g., new A();
- A method can directly be called using this object.
new A().show();
- We can't use the same anonymous object again. It will be use only for one time.
Github repo : github.com/navinreddy20/Javac...
Java:- bit.ly/JavaUdemyTelusko
Spring:- bit.ly/SpringUdemyTelusko
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 - Наука та технологія
Two times constructor running means two new object created.
Got it. 🥳
"Everyone hates this type of people" - Telusko to people who get 99/100 😂😂😂 man ur funny
I'm a big fan of your python tutorial,
need a video on garbage collection
creating an object without reference , which can be deleted by garbage collection ryt?
Whats the use of these anonymous objects?
deep talks
👍
public class Main{
public static void main(String[] args) {//Main method
A a = new A();//Constructor and object creation
a.Announcement();//Method call
new A().Announcement();//Anonymous object and method call
}
}
class A{//parent class
public A(){
//Constructor
System.out.println("
Object created.");
}
public void Announcement(){
System.out.println("NOW in A!");
}
}
I give you 99 for teaching, but I can't hate you😅