Click here to Skip to main content
15,881,967 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
package Demo;

import java.util.Scanner;

public class Demo
	public String name;
	public String mobile;
	public static void met(Demo[] s)
	for(Demo d:s)
	public String toString()
		return name+" "+mobile;
	public static void main(String args[])
		Demo s[]=new Demo[3];
		Scanner demo=new Scanner(;
		for(int i=0;i<s.length;i++)
			s[i]=new Demo();

What I have tried:

explain the output of the following code
Updated 20-Jul-18 2:04am
CHill60 20-Jul-18 7:52am    
No. You run it and see what the output is!

Do you have any idea how much work explaining code line by line is?
Every single line needs a paragraph of explanation! For example:
int next = r.Next();

Create a new variable called "next" which can hold a integer value. From the previously declared Random instance "r", call the "Next" method to get a new random number, and assign it to the "next" variable.

Can you imagine how long it would take us to explain even a very short code fragment like your example, line by line?

No. It is not going to happen. If you have a specific problem, then ask a question about it. But think first - would you want to sit down for 45 minutes and type up a line-by-line description for no good reason?

And besides, this is your homework, not ours: We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
Share this answer
Member 13900790 20-Jul-18 8:07am    
thanks for your reply
OriginalGriff 20-Jul-18 8:31am    
You're welcome!
What will be the output of this following code

There is an easy way to get the answer: Run the code !
explain the output of the following code

The best way to understand what the code is doing is to watch it as it execute, this is exactly what does the debugger.

Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.
Debugger - Wikipedia, the free encyclopedia[^][^][^]
The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900