Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Java Questions and Answers
1. Rumman Ansari || www.atnyla.com Java Language Fundamental
Java Language Fundamental
MCQ Question and Answer
Note: Click to the question to know the answer from our website
www.atnyla.com
2. Rumman Ansari || www.atnyla.com Java Language Fundamental
Q Java is a _________ language.
A. weakly typed
B. strogly typed
C. moderate typed
D. None of these
View Answer
Q Which is a valid keyword in java?
A. interface
B. string
C. Float
D. unsigned
View Answer
Q Which is a reserved word in the Java programming language?
A. method
B. native
C. subclasses
D. reference
View Answer
Q Which will legally declare, construct, and initialize an array?
A. int [] myList = {"1", "2", "3"};
B. int [] myList = (5, 8, 2);
C. int myList [] [] = {4,9,7,0};
D. int myList [] = {4, 3, 7};
View Answer
Q Which one of these lists contains only Java programming language
keywords?
A. class, if, void, long, Int, continue
B. goto, instanceof, native, finally, default, throws
C. try, virtual, throw, final, volatile, transient
D. strictfp, constant, super, implements, do
View Answer
Q Which four options describe the correct default values for array elements of
the types indicated?
1. int -> 0
2. String -> "null"
3. Dog -> null
4. char -> 'u0000'
3. Rumman Ansari || www.atnyla.com Java Language Fundamental
5. float -> 0.0f
6. boolean -> true
A. 1, 2, 3, 4
B. 1, 3, 4, 5
C. 2, 4, 5, 6
D. 3, 4, 5, 6
View Answer
Q Which three are legal array declarations?
1. int [] myScores [];
2. char [] myChars;
3. int [6] myScores;
4. Dog myDogs [];
5. Dog myDogs [7];
A. 1, 2, 4
B. 2, 4, 5
C. 2, 3, 4
D. All are correct.
View Answer
Q
public interface Foo
{
int k = 4; /* Line 3 */
}
Which three piece of codes are equivalent to line 3?
1. final int k = 4;
2. public int k = 4;
3. static int k = 4;
4. abstract int k = 4;
5. volatile int k = 4;
6. protected int k = 4;
4. Rumman Ansari || www.atnyla.com Java Language Fundamental
A. 1, 2 and 3
B. 2, 3 and 4
C. 3, 4 and 5
D. 4, 5 and 6
View Answer
Q Which one of the following will declare an array and initializeit with five
numbers?
A. Array a = new Array(5);
B. int [] a = {23,22,21,20,19};
C. int a [] = new int[5];
D. int [5] array;
View Answer
Q Which three are valid declarations of a char?
1. char c1 = 064770;
2. char c2 = 'face';
3. char c3 = 0xbeef;
4. char c4 = u0022;
5. char c5 = 'iface';
6. char c6 = 'uface';
A. 1, 2, 4
B. 1, 3, 6
C. 3, 5
D. 5 only
View Answer
Q Which is the valid declarations within an interface definition?
A. public double methoda();
B. public final double methoda();
C. static void methoda(double d1);
D. protected void methoda(double d1);
View Answer
Q Which one is a valid declaration of a boolean?
A. boolean b1 = 0;
B. boolean b2 = 'false';
C. boolean b3 = false;
5. Rumman Ansari || www.atnyla.com Java Language Fundamental
D. boolean b4 = Boolean.false();
View Answer
Q Which three are valid declarations of a float?
1. float f1 = -343;
2. float f2 = 3.14;
3. float f3 = 0x12345;
4. float f4 = 42e7;
5. float f5 = 2001.0D;
6. float f6 = 2.81F;
A. 1, 2, 4
B. 2, 3, 5
C. 1, 3, 6
D. 2, 4, 6
View Answer
Q Which is a valid declarations of a String?
A. String s1 = null;
B. String s2 = 'null';
C. String s3 = (String) 'abc';
D. String s4 = (String) 'ufeed';
View Answer
Q What is the numerical range of a char?
A. -128 to 127
B. -(215) to (215) - 1
C. 0 to 32767
D. 0 to 65535
View Answer
Q What will be the output of the program?
public class CommandArgsThree
{
public static void main(String [] args)
{
String [][] argCopy = new String[2][2];
int x;
argCopy[0] = args;
6. Rumman Ansari || www.atnyla.com Java Language Fundamental
x = argCopy[0].length;
for (int y = 0; y < x; y++)
{
System.out.print(" " + argCopy[0][y]);
}
}
}
What will be the output of the program? public class CommandArgsThree {
publ
A. 0 0
B. 1 2
C. 0 0 0
D. 1 2 3
View Answer
Q 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
A. args[2] = 2
B. args[2] = 3
C. args[2] = null
D. An exception is thrown at runtime.
View Answer
Q
public class F0091
7. Rumman Ansari || www.atnyla.com Java Language Fundamental
{
public void main( String[] args )
{
System.out.println( "Hello" + args[0] );
}
}
What will be the output of the program, if this code is executed with the
command line: > java F0091 world
A. Hello
B. Hello Foo91
C. Hello world
D. The code does not run.
View Answer
Q What will be the output of the program?
public class TestDogs
{
public static void main(String [] args)
{
Dog [][] theDogs = new Dog[3][];
System.out.println(theDogs[2][0].toString());
}
}
class Dog { }
A. null
B. theDogs
C. Compilation fails
D. An exception is thrown at runtime
View Answer
Q What will be the output of the program ?
public class Test
{
public static void main(String [] args)
{
8. Rumman Ansari || www.atnyla.com Java Language Fundamental
signed int x = 10;
for (int y=0; y<5; y++, x--)
System.out.print(x + ", ");
}
}
A. 10, 9, 8, 7, 6,
B. 9, 8, 7, 6, 5,
C. Compilation fails.
D. An exception is thrown at runtime.
View Answer
Q What will be the output of the program?
public class CommandArgsTwo
{
public static void main(String [] argh)
{
int x;
x = argh.length;
for (int y = 1; y <= x; y++)
{
System.out.print(" " + argh[y]);
}
}
}
and the command-line invocation is
> java CommandArgsTwo 1 2 3
A. 0 1 2
B. 1 2 3
C. 0 0 0
D. An exception is thrown at runtime
View Answer
Q In the given program, how many lines of output will be produced?
9. Rumman Ansari || www.atnyla.com Java Language Fundamental
public class Test
{
public static void main(String [] args)
{
int [] [] [] x = new int [3] [] [];
int i, j;
x[0] = new int[4][];
x[1] = new int[2][];
x[2] = new int[5][];
for (i = 0; i < x.length; i++)
{
for (j = 0; j < x[i].length; j++)
{
x[i][j] = new int [i + j + 1];
System.out.println("size = " + x[i][j].leng
A. 7
B. 9
C. 11
D. 13
View Answer
Q What will be the output of the program?
public class X
{
public static void main(String [] args)
{
String names [] = new String[5];
for (int x=0; x < args.length; x++)
names[x] = args[x];
System.out.println(names[2]);
}
}
and the command line invocation is
> java X a b
10. Rumman Ansari || www.atnyla.com Java Language Fundamental
A. names
B. null
C. Compilation fails
D. An exception is thrown at runtime
View Answer
Q Size of int in Java is
A. 16 bit
B. 32 bit
C. 64 bit
D. Depends on execution environment
View Answer
Q The implicit return type of a constructor is
A. void
B. A class object in which it is defined.
C. There is no return type.
D. None of the above
View Answer