Java Programming Test 1

What will be the output of the program?

public class CommandArgs

{

public static void main(String [] args)

{

String s1 = args[1];

String s2 = args[2];

String s3 = args[3];

String s4 = args[4];

System.out.print(" args[2] = " + s2);

}

}

and the command-line invocation is

> java CommandArgs 1 2 3 4

> java CommandArgs 1 2 3 4


What is the narrowest valid returnType for methodA in line 3?

public class ReturnIt

{

returnType methodA(byte x, double y) /* Line 3 */

{

return (long)x / y * 2;

}

}


What will be the output of the program?

class Super

{

public int i = 0;

public Super(String text) /* Line 4 */

{

i = 1;

}

}

class Sub extends Super

{

public Sub(String text)

{

i = 2;

}

public static void main(String args[])

{

Sub sub = new Sub("Hello");

System.out.println(sub.i);

}

}


What will be the output of the program?

class SC2

{

public static void main(String [] args)

{

SC2 s = new SC2();

s.start();

}

void start()

{

int a = 3;

int b = 4;

System.out.print(" " + 7 + 2 + " ");

System.out.print(a + b);

System.out.print(" " + a + b + " ");

System.out.print(foo() + a + b + " ");

System.out.println(a + b + foo());

}

String foo()

{

return "foo";

}

}


What will be the output of the program?

int i = O;

while(1)

{

if(i == 4)

{

break;

}

++i;

}

System.out.println("i = " + i);































































































Description:

copyright from: http://www.indiabix.com

Comments

Want to learn?

Sign up and browse through relevant courses.

Name:
Your Email:
Password:
Country:
Contact no:


Area code Number
Subjects you are interested in:
Word verification: (Enter the text as in image)


Sign Up Already a member? Sign In
I agree to WizIQ's User Agreement & Privacy Policy
4 Followers
Tests: 2

Your Facebook Friends on WizIQ

More Tests By Author

Introduction to Java Programming
6 Questions | 140 Attempts

Give live classes, create & sell online courses

Try it free Plans & Pricing

Connect