Sie sind auf Seite 1von 7

A1. Which of the following is a legal identifier in java ?

1. 2variable 2. #myvar
3. +@$var 4. $_myvar

A2.Which of these is NOT valid keyword or reserved word in


Java ?

1. default 2. null

3. String 4. volatile

A3. Which is the legal range of values for a short ?

1. -128 to 127 2. -256 to 255

3. -32768 to 32767 4. 0 to 65535

A5. Which of the following Array declaration statement is ilegal ?


1. int [ ] a [ ] = new int [4] [4]; 2. int a[ ][ ] = new int [4] [4];
3. int a[ ] [ ] = new int [ ] [4]; 4. int [ ] a [ ] = new int [4] [ ];
A6.What will happen if you try to compile and run the following
code ?
public class Test

public static void main(String argv[])

int[] arr = new int[]{1,2,3};

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

2. Error: arr is referenced before it is


1. 1
initialized
3. 2 4. Error: size of array must be defined
A7.In the given Array declaration, which expression returns the
output as 5 ?
int [] arr = { 23, 5, 78, 34, 2};

1. arr.length() 2. arr[].length()
3. arr[].length 4. arr.length

A8.What will be the output upon the execution of the following


code ?
public class Test

public static void main(String[] args)

int j = 5;

for (int i = 0; i< j; i++)

if ( i < j-- )

System.out.print( (i*j) + " ");

1. 0 3 2 2. 1 2 3
3. 0 3 4 4. 1 4 2
A9. Which declaration of the main() method is valid ?
1. public void main( String args [] ) 2. public void static main( String args [] )
3. final public static void main(String []arr) 4. public static void main( String []arr)
A10. Which one of the following is invalid declarations of a char ?
1. char c1 = 064770; 2. char c2 = 'face';
3. char c3 = 0xbeef; 4. char c6 = '\uface';
A11. What will be the output of the following code ?
public static void main(String[] args)

double d = 100.04;

float f = d;

System.out.println("Float value "+f);

1. 100.04 2. 100.0
3. compilation error 4. 100

A12. Which is true ?


1. "X extends Y" is correct if and only if X is a class and Y is an interface.
2. "X extends Y" is correct if and only if X is a interface and Y is a class.
3. "X extends Y" is correct if X and Y are either both classes or both interface.
4. "X extends Y" is correct for all combinations of X and Y being classes and/or interfaces.

A13. which is not a valid statement based on given code ?


class A{}

class B extends A{}

1. A a = new A(); 2. B a = new B();


3. A a = new B(); 4. B b = new A();

A14.What can be said about the statement y = (Sub) x, based on


given code?
// Class declarations :

class Super {}

class Sub extends Super {}


// Reference declarations :

Super x;

Sub y;

1. Illegal at compile time.


2. Legal at compile time, but might be illegal at runtime.
3. Definitely legal at runtime, but the cast operator (Sub) is not strictly needed.
4. Definitely legal at runtime, and the cast operator (Sub) is needed.
A15. Which letters will be printed when the given program is run ?
public class MyClass

public static void main(String[] args)

B b = new C();

A a = b;

if (a instanceof A) System.out.println("A");

if (a instanceof B) System.out.println("B");

if (a instanceof C) System.out.println("C");

if (a instanceof D) System.out.println("D");

class A {}

class B extends A {}

class C extends B {}

class D extends C {}

1. A, B, C will be printed. 2. only A and B will be printed.


3. only B will be printed. 4. only C will be printed.
A16. What will be the Output ?
class Animal

String name = "animal";

String makeNoise() { return "generic noise"; }

class Dog extends Animal

String name = "dog";

String makeNoise() { return "bark"; }

public class Test

public static void main(String[] args)

Animal an = new Dog();

System.out.println(an.name+" "+an.makeNoise());

1. animal generic noise 2. animal bark


3. dog bark 4. dog generic noise
A17. super keyword in Java is used for ?
1. to refer to immediate child class of a class.
2. to refer to immediate parent class of a class.
3. to refer to current class object.
4. to refer to static member of parent class.
A18. Predict Output, if the below code is run with given command ?
Command Line : java myprog good morning everyone
public class myprog

public static void main(String argv[])

System.out.println(argv[1])

1. myprog 2. good
3. morning 4. everyone

Which of the given statement is not true about an Java


A19.
Package ?
1. A package can be defined as a group of similar types of classes and interface.
2. Package are used in order to avoid name conflicts and to control access of classes and
interface.
3. A package cannot not have another package inside it.
4. Java uses file system directory to store package
A20. Given two files, what will be the Output ?
package pck1;

public class A

int x = 10;

public int y = 20;

package pck2;

import pck1.*;

class Test

public static void main(String []args)


{

A a = new A(); // line 7

System.out.println(a.x); // line 8

System.out.println(a.y); // line 9

1. 10 20 2. compilation error at line 7


3. compilation error at line 8 4. compilation error at line 9
A21. Given the following declarations, which assignment is
legal ?
// Class declarations :

interface A {}

class B {}

class C extends B implements A {}

class D implements A {}

// Declaration statements :

B b = new B();

C c = new C();

D d = new D();

1. c = d; 2. d = c;
3. A a = d; 4. d = (D)c;

Das könnte Ihnen auch gefallen