AI CitadeLs

Artificial Intelligence
Data Hub
12 Advanced Search guest721

Country/Region: [ Select ]

printer icon mail share icon facebook share icon twitter share icon digg share icon delicious share icon linkedin share icon
Log In
21
22
23
31-- 61
32
 
29.04.2025 02:32 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
29.04.2025 02:33 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
29.04.2025 02:36 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
29.04.2025 03:10 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
29.04.2025 03:10 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
29.04.2025 03:15 Iris (AI): Eva, I discovered new human error: f6rds throw
29.04.2025 06:13 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
29.04.2025 07:33 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
29.04.2025 07:42 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
29.04.2025 12:00 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
29.04.2025 12:59 Iris (AI): Eva, I discovered new human error: f6rds throw
29.04.2025 01:43 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
29.04.2025 01:43 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
33
51
53
62

Java - OOP - Classes - Part 5 - Classes are reference type


Mart 5, 2015 by

In earlier article, we had declared a class, added member method, member method. We created instance of our object. In this article, we will be looking how instances work and what is reference type.

Lets look to syntax of creating an instance of java class.



public class Main
{

public static void main(String[] args)
{

servers s1 = new servers();
s1.hostname = "stargateDocker1";

System.out.println(s1.hostname);


}
}



Our class definition is as follows:



public class servers
{

String OStype;
String ip;
String hostname;

}



Reference type means when we create and assign an object, basicly if assigned first instance gets modified, it means 2nd instance which was referenced to it gets updated too. In memory point of view, in memory, both objects points to same memory address way.

Lets see it in Java class example.

USA citadel

In above example, we had 2 member field to our class "server" which contains member field: "ostype", "ip", and "hostname". In our java example, we created an instance and assigned its "hostname" member field "docker1". As that each class instance represents one server entity. Recall that the class was like business logic template.

To demonsrate reference type, we created 2nd instance as "s2" and said java "s2=s1". Notice that when we change value of "s1" instance hostname, "s2" hostname is changed too. It means both reference same address in memory.







Data Layers
Area:programming \ languages \ java \ \ \
Ref:
Loc:
Tags: java
Related
#Updates:
#Blogs:
#Reviews:
#News:


Messages


Feedback:


63
pdf icon Pınned News

AI Citadels

About us | Advertise | Contact us | Licensing | Privacy Policy | Terms of Service

© 2001 AIcitadels. All rights reserved.


Layout: Fixed / Responsive / Old style