473,516 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is diff between creation of obj & creation of ref varable

3 New Member
What is diff between

Class c=new Class(); //Create object

and

Class c;
c=new Class(); //create reference variable
Sep 8 '09 #1
4 1304
tlhintoq
3,525 Recognized Expert Specialist
No difference...........................
Sep 8 '09 #2
panks
3 New Member
How thete is no diff plz explain,coz i am very confusing about that.
Sep 9 '09 #3
GaryTexmo
1,501 Recognized Expert Top Contributor
All objects that aren't value types are references, I believe.

So just like...
Expand|Select|Wrap|Line Numbers
  1. int x = 0;
...is the same as...
Expand|Select|Wrap|Line Numbers
  1. int x;
  2. x = 0;
... for a value type, what you have is exactly the same for a reference type.

Is there any particular problem you're running into with regards to this? Maybe if you were having an issue, and explained it, we could define things in terms better applicable to you :)
Sep 9 '09 #4
tlhintoq
3,525 Recognized Expert Specialist
@panks
What are you confused about?

Expand|Select|Wrap|Line Numbers
  1. Class c;
  2. // Creates a new class named C but gives it no value.
  3.  
  4. c=new Class(); //create reference variable
  5. //Initializes your c giving it the value of a new Class().  This will call the creation method of the class to initialize any values within the class.
As Gary pointed out in a simpler example (not a class)
Expand|Select|Wrap|Line Numbers
  1. int x;  // An int is created but given no value
  2. x = 5;  // The value of x is assigned to x
  3.  
  4. // Same end result as
  5. int x = 5; // A new int is created then assigned the value of 5 all in one line.
  6.  
Sep 9 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

16
2563
by: Jason | last post by:
Hey, I'm an experience programmer but new to Python. I'm doing a simple implementation of a field morphing techinique due to Beier and Neely (1992) and I have the simple case working in Python 2.3 - but it's REALLY slow. Basically, you specify two directed line segments in the coordinate system of a raster image and use the difference...
4
1825
by: Graham Mattingley | last post by:
Hello I have this coden (below), that I found that works really well when to prove a URL is valid, or any object in a URL. They way it works is that you submit the URL through a form, txtURL is the varable... What I want to be able to do is have a database of URLs and loop through them with this in the middle and check all the URLs I have...
9
6502
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the delta binary is pretty huge in size. I have 1 byte file and 2 bytes file, the delta should be 1 byte but somehow it turns out to be 249 bytes using...
1
2042
by: Gary | last post by:
Open the web browser at the same time, the session varable in the second broswer is disappeared. All The Session Varable is declared in the webform page load.
6
5139
by: ppravin88 | last post by:
hi guys 'n' gals .. could anyone tell me the difference between getch(); and getche(); and when and where should we use this function... and also wat is the diff between return(); & return(0); & return(1);..........
2
1604
by: Suresh Kumar Rathod | last post by:
HI friends... Can any body give reason / logic behind static varable lifetime through out the process execution. i.e how does compiler maintains the static varable life through out the process execution ? example #include<stdio.h>
2
1266
by: =?utf-8?B?5Lq66KiA6JC95pel5piv5aSp5rav77yM5pyb5p6B | last post by:
Please see the followed example: class A: def __init__(self): pass class X: def __init__(self): n = 200 if True: j = 200
0
2494
by: KJ | last post by:
Helo All, Does anyone out there have any example XSLT files (that they'd like to share) which transform difgrams produced by the Xml Diff and Patch tool into a nice format? This would be most appreciated. -Thanks, KJ
1
1218
by: Yogesh Sharma | last post by:
Diff B/w Windows & SQL Server Authentication. Which one is trusted & which one is not?
0
7182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7408
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7142
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7548
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5714
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4773
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3259
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1624
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.