473,386 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Can someone tell what is happening in the code

Can someone tell why is variable a not getting printed.
Expand|Select|Wrap|Line Numbers
  1. import java.lang.*;
  2. import java.io.*;
  3. class t
  4. {
  5.         int a=5;
  6.         void fun()
  7.         {
  8.                 System.out.println(a);
  9.         }
  10.         public static void main(String args[])
  11.         {
  12.         }
  13.         t()
  14.         {
  15.                 t var = new t();
  16.                 var.fun();
  17.         }
  18. }
  19.  
  20.  
Sep 25 '15 #1
3 1374
q88qaz
1
Nothing ouput.
The main methoed is null,did nothing.
Sep 25 '15 #2
But i was printing a in fun
Sep 25 '15 #3
chaarmann
785 Expert 512MB
You "were printing a in fun" only if you would have called it in main. But you never called it. That's why it did not print.

See, you opened method main in line 11 and directly closed it in line 12. Nothing in between. But if you want to print, then you have to insert "new t()" there.

In line 13 the constuctor starts. It is executed if you call "new t()". Inside the constructor, in line 15, you call the constructor again! Endless-recursion will let it crash! So just delete line 15 and only call "fun()" in line 16 to make it work. Or just move line 15 and 16 unchanged between 11 and 12.
Sep 28 '15 #4

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

Similar topics

21
by: MLH | last post by:
A97 procedure to open http://www.arch.com/message/ enter an 800 number, press "Continue", enter a text msg string from a memo field and press "Send" This is a calendaring and appointment A97...
2
by: Just Me | last post by:
Dim iData As IDataObject = Clipboard.GetDataObject() Dim img As System.Drawing.Bitmap img = img.FromFile(ofd.FileName, True) Clipboard.SetDataObject(img) TextControl1.Paste() img.Dispose() : img...
5
by: garyusenet | last post by:
I understand that Point is an object used for storing co-ordinates, such as mouse location. I can't figure out what the e's do in the above example can someone explain please. Thanks, Gary.
2
by: Sridhar Pettela | last post by:
i cannot how can i modify the login control and connecting with the SQLServer 2000, can any one tell the code of login control and about login tab SRIDHAR.P *** Sent via Developersdex...
6
by: rlueneberg | last post by:
Can someone tell if Sitemap always require a starting root? Can it have more than one root? I am having a problem trying to hide a root node without hiding its children using a Treeview component....
2
by: ppuniversal | last post by:
Hello, Can someone tell a good Tutorial on Network Programming in C++, except Beej's Guide and Vijay Mukhi's tutorials. I want to make a Client Server application in C++ which will involve...
23
by: jagmonni | last post by:
hi everybody, i need to do a website in php so i need a functionality of sending SMS to mobiles. So could anyone please send me the website link for registering the SMS Gateway in India. ...
0
by: Saboor Mohideen | last post by:
Can someone tell me which event occurs on Total TextBox: Main Form Name Type Event Used Event Set All three textboxes are bound to a table CashAmount TextBox ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.