QuizJAVA1

download QuizJAVA1

of 5

Transcript of QuizJAVA1

  • 8/7/2019 QuizJAVA1

    1/5

    QUIZ

    GLNA Institute of Technology, Mathura

    Sub: Object Oriented Technique

    Branch/Year/Sem-CS/III/V

    Time: 30 Minutes Max.

    Marks:20

    Mark Correct Answer in the given table

    Q 1) Which of the following lines will compile without warning or error.a)float f=1.3; b) char c="a"; c) byte b=257; d) int i=10;

    Q2) Which of the following will compile without errora) importjava.awt.*;packageMypackage;class Myclass {}

    b)package MyPackage;imported java.awt.*;class MyClass{}

    c)/*This is a comment */package MyPackage;import java.awt.*;class MyClass{}

    Q3) What will be printed out if this code is run with the following command line?java myprog good morningpublic class myprog{public static void main(String argv[])

    {System.out.println(argv[2])}}a) myprog b) good c) morning d) Exception raised:java.lang.ArrayIndexOutOfBoundsException: 2"

    Q4)Which of the following are not a keywords or reserved words in Java?a) if b) then c) gone d) while

    Q5)Which of the following is not a legal identifiers

    a)variable b) 4_ variable2 c) _whatavariable d) _3_

    Question a b c D Question a b c d

    1 11

    2 12

    3 13

    4 14

    5 15

    6 167 17

    8 18

    9 19

    10 20

  • 8/7/2019 QuizJAVA1

    2/5

    Q6)If you wanted to find out where the position of the letter v (ie return 2) in thestring scontaining "Java", which of the following could you use?

    a) mid(2,s) b) charAt(2) c) s.indexOf('v') d) indexOf(s,'v')

    Q7) An Applet has its Layout Manager set to the default of FlowLayout. Whatcode would be correct to change to another Layout Manager.(a) setLayoutManager(new GridLayout()); (b) setLayout(new GridLayout(2,2));(c) setGridLayout(2,2) (d) setBorderLayout();

    Q.8)By default, all program import(a) java.lang (b)java.awt (c)javax.objex (d)java.swing

    Q.9) a variable inside an Interface will be(a)final (b)static (c)both a & b (d)none

    Q.10) Which method is used to set the text of a Label object?

    (a) setText( ) (b)setLabel( ) (c)setTextLabel( ) (d)setLabelText( )

    Q12)What is the default Layout Manager for the Frame?

    (a) BorderLayout() (b)GridLayout() FlowLayout() (d)none

    Q13) Which one is not a Applets Life Cycle methods?(a)init() (b)start() (c)stop() (d)destroys()

    Q14) What is the difference between the Reader/Writer class hierarchy and the

    InputStream/OutputStream class hierarchy?

    a) The Reader/Writer class hierarchy is character-oriented and the InputStream/OutputStream class

    hierarchy is byte-oriented.b) The Reader/Writer class hierarchy is byte-oriented and the InputStream/OutputStream class

    hierarchy is chracter-oriented.

    c) Both are character-oriented.

    d) Both are byte-oriented.

    Q15) What value does read( ) return when it has reached the end of a file?

    a) 1 b) 1 c)-1 d) 1

    Q16) What is the result of expression 5.45 + "3,2"?

    (a)The double value 8.6 (b)The string ""8.6" (c)The long value 8. (d)The String "5.453.2"

    Q17) The new operator is used to create.

    a)class b) object c) interface d)none

    Q18) A -------------- is automatically called when an object is instantiated

    a) Constructor b) final c)finally d)none

    Q19)UML stands for

    (a)Unified modelling language b)unified model language c)universal modelling language d)none

    Q20)Which statement is correct(a)use case is realized by collaboration diagram (b)Use case is a set of action (c)both (d)none

  • 8/7/2019 QuizJAVA1

    3/5

    Ans:18-a

    Ans17-a

    ANS 10- : a.

    11- BorderLayout().

    Ans13-a

    Ans15-d

  • 8/7/2019 QuizJAVA1

    4/5

    A.1explanation:1) float f=1.3;Will not compile because the default type of a number with a floating pointcomponent is a double. This would compile with a cast as infloat f=(float) 1.3

    A2-2 and 3 will compile without error.

  • 8/7/2019 QuizJAVA1

    5/5

    1 will not compile because any package declaration must come before any othercode. Comments may appear anywhere.

    Q3-4) Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2"Unlike C/C++ java does not start the parameter count with the program name. Itdoes however start from zero. So in this case zero starts with good, morningwould be 1 and there is no parameter 2 so an exception is raised.Q4-Objective 1.5)1) if3) goto4) while5) case

    then is not a Java keyword, though if you are from a VB background you mightthink it was. Goto is a reserved word in Java.Q5An identifier can begin with a letter (most common) or a dollar sign($) or an

    underscore(_). An identifier cannot start with anything else such as a number, ahash, # or a dash -. An identifier cannot have a dash in its body, but it may havean underscore _. Choice 4) _3_ looks strange but it is an acceptable, if unwiseform for an identifier.

    6) 3-s.indexOf('v');charAt returns the letter at the position rather than searching for a letter andreturning the position, MID is just to confuse the Basic Programmers,indexOf(s,'v'); is how some future VB/J++ nightmare hybrid, might perform sucha calculation.

    Q72) setLayout(new GridLayout(2,2));

    Changing the layout manager is the same for an Applet or an application. Answer1 is wrong though it might have been a reasonable name for the designers tochoose. Answers 3 and 4 are incorrect because changing the layout manageralways requires an instance of one of the Layout Managers and these are bogusmethods.Instead of creating the anonymous instance of the Layout manager as in option 2you can also create a named instance and pass that as a parameter. This is oftenwhat automatic code generators such as Borland/Inprise JBuilder do.