cancel
Showing results for 
Search instead for 
Did you mean: 

Command line argument

Former Member
0 Kudos

Hello ! i m a beginner in java. Kindly help me in solving this code

wat'll be happen when you compile ant run this code??

public class Arg{

String MyArg;

public ststic main(String argv[]){

Myarg=argv;

}

public void amethod(){

System.out.println(argv[1]);

}

}

Options----

1. Compile time error

2. Compilation and output of "hello"

3. Compilation and output of "there"

4. None of the above

Accepted Solutions (1)

Accepted Solutions (1)

Torsten_
Advisor
Advisor
0 Kudos

Hello

the problems you posted here are normal java problems.

Look the google java groups formu:

<a href="http://groups.google.com/group/comp.lang.java.programmer?lnk=sg&hl=en">Googel java group</a>

Here is the runable code from your posted problem:

public class Arg extends Base  {
	
	// this is an instance member
	String MyArg;
	
	public static void main(String argv[]){
		
		// first you need an instance
		Arg arg = new Arg();
		
		arg.MyArg = argv[0];
	}
}

Torsten

Answers (1)

Answers (1)

Former Member
0 Kudos

Payal,

Seems that you are misusing SDN forums.

You are not learning Java, you just have to pass some tests either to get a work or to pass a certification.

In either way, you have selected "short way" (wrong one), and instead of learning Java you are using forum to collect answers. By the way, wrong answers like here: If you or Mukesh run the program, you will see that the values are printed.

Instead of this, get a good book on Java (like "Thinking in Java" from Bruce Eckel), install JDK and some IDE and study the language.

VS