Вы находитесь на странице: 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

Question a b c D Question a b c d
1 11
2 12
3 13
4 14
5 15
6 16
7 17
8 18
9 19
10 20

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 error


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

Q3) What will be printed out if this code is run with the following command line?
java myprog good morning
public 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_
Q6)If you wanted to find out where the position of the letter v (ie return 2) in the
string s
containing "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. What
code 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 Applet’s 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
Ans:18-a
Ans17-a

ANS 10- : a.
11- BorderLayout().
Ans13-a
Ans15-d
A.1explanation:
1) float f=1.3;
Will not compile because the default type of a number with a floating point
component is a double. This would compile with a cast as in
float f=(float) 1.3
A2-2 and 3 will compile without error.
1 will not compile because any package declaration must come before any other
code. 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. It
does however start from zero. So in this case zero starts with good, morning
would be 1 and there is no parameter 2 so an exception is raised.
Q4-Objective 1.5)
1) if
3) goto
4) while
5) case

then is not a Java keyword, though if you are from a VB background you might
think 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, a
hash, # or a dash -. An identifier cannot have a dash in its body, but it may have
an underscore _. Choice 4) _3_ looks strange but it is an acceptable, if unwise
form for an identifier.

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

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

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

Вам также может понравиться