搜档网
当前位置:搜档网 › 答案3

答案3

PART A (70 * 1 = 70 Marks)



(Note: Choose the best answer. Write only the answer.)



In Java, when a program is compiled, it is converted into ------______

a) Machine code b) Byte code c) Hexadecimal code

d) None of the above.

(ans: b)



The ______ is the mechanism that binds the data and functions together with each

other and keeps both safe from outside interference.

a) Encapsulation b) Polymorphism c) Inheritance d) None

(ans: a)



Java programs should be saved with the extension

a) .c b) .txt c) .java d) .doc

(ans: c)



______ do not cause the computer to perform any action when the program is run.

a) Comments b) The keyword Class c) Main method d) None

(ans: a)



When -------________ appears in a string of characters, Java combines the next

character and forms the escape sequence.

a) front slash ( / ) b) back slash ( \ ) c) comments d) None

(ans: b)



Java’s numerous predefined classes are grouped into categories or related classes

called ______

a) Objects b) Classes c) Library d) Packages

(ans: d)



The name of the package with “java” is called

a) Core packages b) Extension packages c) Both a & b

d) None

(ans: a)



The _______ class provides prepackaged dialog boxes that enables us to display

boxes.

a) JApplet b) Graphics c) Container d) JoptionPane

(ans: d)



The ________ statement is used to include all the necessary classes into our

program from the specified package.

a) class definition b) import c) main definition d) None

(ans: b)





_______ is the method which is used to read the value from the user which comes

under the class JoptionPane.

a) showMessageDialog( ) b) showInputDialog( ) c) System.out

d) System.in

(ans: b)



The method which is used to convert the String value to Integer value

a) parseDouble b) parseInt c)parseFloat d)none

(ans: b)

12. What will be printed out if you attempt to compile and run the following code ?

int i=1;


switch (i)


{


case 0:


System.out.println("zero");


break;


case 1:


System.out.println("one");


case 2:


System.out.println("two");


default:


System.out.println("default");


}


1) one
2) one, default
3) one, two, default
4) default

(ans: 3)




13. int i=9;


switch (i)


{


default:



System.out.println("default");


case 0:


System.out.println("zero");


break;


case 1:


System.out.println("one");


case 2:


System.out.println("two");


}


1) default
2) default, zero
3) error default clause not defined
4) no output displayed

(ans: 2)

14. Which correctly create a two dimensional array of integers?

(a)int a[][] = new int [10,10];

(b)int a[10][10] = new int [][];

(c) int a[][] = new int [10][10];

(d) int []a[] = new int [10][10];

(ans: c)









15. We have the following code:

if (a >4)

System.out.println("test1");

else if (a >9)

System.out.println("test2");

else

System.out.println("test3");

What will print 'test 2'?

A. less than 0

B. less than 4

C. between 4 and 9

D. greater than 9

E. None of the above

(ans: e)

16. Which one does not extend https://www.sodocs.net/doc/3710526133.html,ng.Number

a)Integer

b)Boolean

c)Character

d)Long

e)Short

(ans: b and c)



17. Public class Cycle

{ public static void main(String args[]){

System.out.println(args[0]);

}

}

. if we compile our program by java Cycle one two, what will be output?

a) cycle

b) one

c) two

d) none

(ans: b )

18. Which of the following are NOT Java modifiers?

a) public

b) private

c) friend

d) transient

(ans: 4)



19. What is the result of executing the following code when the value of x is 2:

switch (x)

{

case 1:

System.out.println(1);

case 2:

case 3:

System.out.println(3);

case 4:

System.out.println(4);

}

Select the most appropriate answer.

(a) Nothing is printed out

(b) The value 3 is printed out

(c) The values 3 and 4 are printed out

(d) The values 1, 3 and 4 are printed out

(ans: c)



20. What does the zeroth element of the string array passed to the public static void main method contain?

Select the most appropriate answer

(a) The name of the program

(b) The number of arguments

(c) The first argument if one is present

(d) none of the above

(ans: c)

21. What will be the result of compiling the following code:

public class Test

{

static int age;

public static void main (String args [])

{

age = age + 1;

System.out.println("The age is " + age);

}

}

Select the most appropriate answer.

(a) Compiles and runs with no output

(b) Compiles

and runs printing out The age is 1

(c) Compiles but generates a runtime error

(d) Does not compile

(e) Compiles but generates a compile time error

(ans: b)

22. Which of the following return true?

Select all correct answers.

(a) "john" == "john"

(b) "john".equals("john")

(c) "john" = "john"

(d) "john".equals(new Button("john"))

(e) none of the above

(ans: a,b )

23. What is the result of executing the following code, using the parameters 4 and 0:

public void divide(int a, int b)

{

try

{

int c = a / b;

} catch (Exception e)

{

System.out.print("Exception ");

} finally

{

System.out.println("Finally");

}

}

Select the most appropriate answer.

(a) Prints out: Exception Finally

(b) Prints out: Finally

(c) Prints out: Exception

(d) No output

(ans: a)

24. Which Exception will be generated if the array size is mentioned as negative?

(a) ArrayIndexOutOfBoundsException

(b) NegativeArraySizeException

(c) NumberFormatException

(d) IOException

(ans: b)

25. Which of the following methods are defined on the Graphics class:

Select all correct answers.

(a) drawLine(int, int, int, int)

(b) drawImage(Image, int, int, ImageObserver)

(c) setVisible(boolean);

(d) none of the above

(ans: a, b)



26. Given the following code what is the effect of ‘a’ being 5:

public class Test

{

public void add(int a)

{

for (int i = 1; i < 3; i++)

{

for (int j = 1; j < 3; j++)

{

if (a ==5)

{

break;

}

System.out.println(i * j);

}

}

}

}

Select the most appropriate answer.

(a) Generate a runtime error

(b) Throw an out of bounds exception

(c) Print the values: 1, 2, 2, 4

(d) Produces no output

(ans: d)

27. What is the result of executing the following fragment of code:

boolean flag = true;

if (flag = true)

{

System.out.println("true");

}

else

{

System.out.println("false");

}

Select the most appropriate answer.

(a) true is printed to standard out

(b) false is printed to standard out

(c) An exception is raised

(d) Nothing happens

(ans: a )



28. What happens when the following program is compiled and executed with the arguments java test. Select the one correct answer.

class test

{

public static void main(String args[])

{

if(args.length > 0)

System.out.println(args.length);

}

}

(a) The program compiles and runs but does not print anything.

(b) The program compiles and runs and prints 0

(c) The program compiles and runs and prints 1

(d) The program compiles and runs and prints 2

(e)

The program does not compile.

(ans: a)

29. What will be the output of the program

int j = 1;

while(j<5)

{

if(j == 1)

continue;

j++;

}

a) 1 b) 2, 3, 4 c) infinite loop d) 2, 3, 4, 5

(ans: c)



30. The ______is a quantity whose value does changes during program execution

a) Variable b) constant c) expression d) none

(ans: a)



31. What is the output of the following fragment.

int a = 11, b = 3, c;

c = a % b;

System.out.println( c );

a) 3 b) 2 c) 4 d) none

(ans: b)



32. What is the output of the following fragment.

int a = 2 * (5 – 1) / (2 +1 );

System.out.print( a );

a) 2 b) 1 c) 3 d) none

(ans: a)



33. What is the output of the following fragment.

int a = 2;

System.out.println( a++);

System.out.println( a);

System.out.println(++a);

a) 3, 3, 3 b) 3, 3, 4 c) 2, 3, 4 d) 2, 3, 3

(ans : c)

34. ________ are the Java programs that can be embedded in HTML.

a) Applets b) Applications c) JDK d) none

(ans : a)



35. ________ is responsible for building Graphical User Interface

a) JApplet b) AWT c) JOptionPane d) none

(ans : b)

36. ----------------- is nested in a class definition within another class and treated


like any other method of that class.


(a) inner class (b) static class (c)final class (d) none of the above


(ans: a)





37. ------------- Returns a new string object containing the original


string of characters followed by the characters in the argument..


(a) concat() (b) charAt() (c) endsWith( ) (d) none of the above


(ans: a)





38. ------------------ is the process of deriving a class from a super


class or a base class.


(a) Polymorphism (b) Inheritance (c) encapsulation( ) (d) none


(ans: b)





39. The attributes and methods declared as ------------ in the base


class can be accessed within the class and any of its derived class.


(a) public (b) private (c) protected( ) (d) none of the above


(ans: c and a)





40. -------------- is the creation of a method in the subclass that has the same


signature, i.e., name, number and type of arguments, as a method in the super


class.


(a) overloading (b) overriding (c) inheritance ( ) (d) none


(ans: b)





41. The class can be declared as ------------, if instances or subclasses are not to be


created.


(a) final (b) static (c) abstract ( ) (d) none of the above


(ans: a)





42. ----------------- is an abnormal condition, which occurs during the exe

cution of


a program.


(a) error (b) static (c) exception (d) none of the above


(ans: c)





43. ----------- block provides code that always executes, regardless of whether an


exception occurs or not.


(a) try (b) catch (c) finally (d) none of the above


(ans: c)





44. ------------- exception is generated on entering characters as input.


(a)NumberFormatException (b) ArrayIndexOutOfBoundsException


(c) IOException (d) none of the above


(ans: a)





45. -------- contain a set of classes in order to ensure that class names are unique.


(a)Packages (b) programs (c) subclasses (d) none of the above


(ans:a)





46. ------------- tag is used to pass parameters in an applet.


(a) Parameters (b) PARAM (c) VALUE (d) none of the above


(ans:b)





47. Initialization of all variables, creation of objects, setting of parameters, etc.


can be done in the ---------- method.


(a) init (b) start (c) stop (d) none of the above


(ans: a)


48. --------------- method loads an image from an URL which specifies the


location from which the image is to be loaded.


(a) loadImage (b) getImage (c) drawImage (d) none of the above


(ans: b)





49. In a ------------- system, only one part of the program is in the process of


execution at any one time.


(a) single - threaded (b) multi-threaded (c) double-threaded (d) none


(ans:a)





50. A ----------- is an object that implements a specific EventListener interface


extended from the generic java.util.EventListener.


(a) thread (b) event (c) Listener (d) none of the above


(ans:c)





51. ----------- keyword is used, If we need to access the methods or variables in the


parent class whose method name is same to that of the derived class.


(a) super (b) this (c) static (d) none of the above


(ans:a)





52. A -------------- is a method that is called when an object is created.


(a)this (b) constructor (c) start (d) none of the above


(ans:b)





53. The -------- is used to find out the class name to which the object belongs.


(a)getObject (b) class (c) getClass (d) none of the above


(ans:c)





54. The ------- keyword can be used where a reference to an object of the current


class type is required.


(a)super (b) this (c) new (d) none of the above


(ans:b)





55. ------------- keyword is used to declare a class variable.


(a)super (b)

this (c) static (d) none of the above


(ans:c)





56. The ------- operator creates a single instance of a named class and return a


reference to that object.


(a)super (b) this (c) new (d) none of the above


(ans:c)





57 The process of locating a particular element value in an array is called -----------.


(a)arranging (b) sorting (c) searching (d) none of the above


(ans:c)





58---------------sort is to successively compare adjacent elements and swap them


if they are out of order.


(a)bubble (b) random (c) linear (d) none of the above


(ans:a)





59. ---------- can be defined as a collection of variables of same type that are


referred to by common name.


(a)collection (b) array (c) set (d) none of the above


(ans:b)





60. The --------- statement, when executed in a while, for, do-while or switch


structure caused immediate exit from the structure.


(a)break (b) continue (c) loop (d) none of the above


(ans:a)





61. In ---------- loop, the condition is checked at the last.


(a)while (b) do-while (c) loop (d) none of the above


(ans:b)





62. ---------- method is used for finding the exponentiation of a number.


(a)pow (b) exp (c) power (d) none of the above


(ans:a)


63. ----------- symbol is used to assign the value which is in the right hand side to the


variable which is in the left hand side.


(a)= (b) == (c) <> (d) none of the above


(ans:a)





64. ------------- is the default browser which supports Java 2.


(a)internet explorer (b) netscape navigator (c) oprah (d) none


(ans:b)





65. ------------- relational operator is used for representing "not equal to" condition.


(a)` (b) != (c) <> (d) none of the above


(ans:b)





66. ________ method is used to obtain the path of .class file


(a) getCodeBase( ) (b) getClass( ) (c) getDocumentBase( ) (d) none


(ans:a)








67. The -------- statement, when executed in a while, for or do-while structure, skips


the remaining statements in the loop body and proceeds with the next iteration


of the loop.


(a)break (b) continue (c)loop (d) none of the above


(ans:b)





68.An array index starts with -----


(a)0 (b) 1 (c)-1 (d) none of the above


(ans:a)





69. The -------- methods and variables cannot be seen by any class other than the one in


which they are defined.


(a)protected (b)public (

c)private (d) none of the above


(ans:c)





70.------------- is used to accept input from the user.


(a)stream (b)InputStreamReader (c)outputstreamreader (d) none


(ans:b)




PART B (2 * 10 = 20 Marks)

(Note: Write any 2 programs from the following questions.)

1. Write a program to sort the given array in Ascending order

2. Write a program to draw the given shapes in the Applet

a) Line

b) Rectangle

c) Polygon

d) Arc

e) Oval

3. Write an error handling program to divide two numbers when divided by zero



PART C (1 * 10 = 10 Marks)



(Note: Find out the errors in the following program and write down the correct program.)

1.

import javax . awt . *;

public class nonstaticmethod

{

String x, y;

static int z;

void getdata()

{

int a, b;

a = JOptionPane.showInputDialog("Enter the first no");

b = JOptionPane.showInputDialog("Enter the second no");

x = Integer.parseInt(a);

y = Integer.parseInt(b);

}

 

void display()

{

system.out.println(" The result of x + y is " + (x+y));

}

Public Static Void Main(string args[])

{

nonstaticmethod obj1 = new nonstaticmethod();

getdata();

display();

z = 10000;

System.out.println("The value of class variable z is " + z );

}

}



Answers- Part B


1. // Example to explain bubble sorting



import javax.swing.JOptionPane;



public class bubblesort

{

public static void main(String args[])

{

int a[]=new int[10];

String b[]=new String[10];

int i,j,t;

String output="";



for(i=0; i<10; i++)

{

b[i]=JOptionPane.showInputDialog("Enter the " + i+"th number");

a[i]=Integer.parseInt(b[i]);

}



for(i=0;i<10;i++)

{

for(j=0; j<10-1; j++)

{

if( a[j] > a[j+1] )

{

t=a[j];

a[j]=a[j+1];

a[j+1]=t;

}

}

}

output += "The array elements in Ascending order\n";



for(i=0; i<10; i++)

output += a[i] + " ";

JOptionPane.showMessageDialog(null,output,"Result",https://www.sodocs.net/doc/3710526133.html,RMATION_MESSAGE);

System.exit(0);

}

}



2. // This file is saved as shapes.java

import java.awt.Graphics;

import javax.swing.JApplet;



public class shapes extends JApplet

{

// for draw polygon



int xs[] = {40,49,60,70,57,40,35};

i

nt ys[] = {260,310,315,280,260,270,265};



public void paint(Graphics g)

{

g.drawLine(40, 30, 200, 30);

g.drawRect(40, 60, 70, 40);

g.drawOval(240,120,70,40);

g.drawArc(140,180,70,40,0,180);

g.drawPolygon(xs,ys,7);

}

}

// This file is saved as shapes.html















3. // Arithmetic Exception



public class arithexcep

{

public static void main(String args[])

{

int a= 5, b= 0 , c;

try

{

c = a/b;

System.out.println("Result = " + c);

}catch(ArithmeticException n)

{

System.out.println("Generated Exception is : " + n);

}

}

}


Answer - Part – C


1.

import javax.swing.JOptionPane;



public class nonstaticmethod

{

int x, y;

static int z;

void getdata()

{

String a, b;

a = JOptionPane.showInputDialog("Enter the first no");

b = JOptionPane.showInputDialog("Enter the second no");

x = Integer.parseInt(a);

y = Integer.parseInt(b);

}



void display()

{

System.out.println(" The result of x + y is " + (x+y));

}



public static void main(String args[])

{

nonstaticmethod obj1 = new nonstaticmethod();

obj1.getdata();

obj1.display();

z = 10000;

System.out.println("The value of class variable z is " + z );

System.exit(0);

}

}

相关主题