Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
2. Which is the correct expression to be used to read line by line and store the
result into a String object
a) File f = new File("test.txt");
5. Which state decide a var. ’a’ which is suitable for referring to an array of 50
string objects?
a. char a[ ] [ ];
b. String a [ ];
c. String [ ] a;
d. Object a [50];
e. String a[50];
private int i;
method() ;
int j;
j= i;
long A = 9;
long B = 9;
a. L9 == L10
b. L9 == L11
c. L10 == L11
d. A == L9
e. A == B
9. How should we make a class to handle the events generated by a single user
interface component?
10. What are the assignments which are valid in the line XXXX
class Super{
private int i;
public int ma_cd(float f){
i = (int) f;
return i; }}
class Sub extends Super{
int j;
float g;
public Sub(){
Super s = new Super();
XXXX }
}
a. j = i;
b. g = f;
c. j = s.ma_cd(3.2f);
d. j = s.i;
e. g = s.f;
if (a==1) {
break inner;
a. a is 0 x is 0
b. a is 0 x is 1
c. a is 0 x is 2
d. a is 1 x is 0
e. a is 1 x is 1
f. a is 1 x is 2
g. a is 2 x is 0
h. a is 2 x is 1
i. a is 2 x is 2
12. Which is the earliest possible instance that Garbage Collection is activated
for String created in line 1.
public static void main(String args[ ]){
1. String s = "abcd";
2. String s1 = "efghi";
3. String s2 = s+ s1;
4. s = null;
5. s = s1;
6. s1 = s;
a. Before Line 3.
b. Before Line 4.
c. Before Line 5.
d. Before line 6.
13. There is a plan to prepare a class which is going to used in many unrelated
parts of the project. The class should be Polygon object which is a Shape. The
polygon has a information about the coordinates stored in a vector, color status
which states whether true or false. Write a class declaration which describes the
above
public class Polygon extends Shape{
vector coord;
boolean colorstatus;
a. Vector
b. Date
c. Object
d. Person
e. Employee
f. Int
a. File
b. InputStream
c. DataInputStream
d. BufferedReader
e. InputStreamReader
0x7
17. What is the output of the following program Example if args[0] is printed
a. dog
b. cat
c. Example
d. java
e. Null PointerException is thrown
a. private
b. default (no access modifier specified)
c. protected
d. public
e. static
a. if a component has been given fill both is true, then as the container
resizes the component resizes
b. The number of rows and columns are fixed while loading the components.
c. The number of rows and columns are fixed while loading the layout itself .
d. if a component has a non-zero weighty value, then the component grows in
height as the container is resized.
Case 2:
a. 1
b. 2
c. 3
d. 4
e. 0
21. If the string array name is argc in the arguments in the main method, which is
invoked by the interpreter when a program is executed
a. char string [ ] [ ]
b. char [ ] a [ ]
c. char a[ ]
d. String argc
e. String argv[ ]
f. String argc[ ]
24. How will you override or overload the following method method1 of the Super
class in the class Sub?
class Super{
System.out.println("Test 2");
} else
System.out.println("Test 3");
a. 0 to 4
b. Less than 0
c. 5 to 9
d. Greater than 10
a. FlowLayout
b. GridLayout
c. GridBagLayout
d. East or West of BorderLayout
e. North or South of BorderLayout
31. What is the access modifier for a class member variable which is to be used
in the same package where the class is defined
a. protected
b. private
c. public
d. no access modifier
e. static
a. run
b. begin
c. execute
d. start
e. resume
do {
}while(--i > 0)
System.out.println("Finished");
a. The value of i is 1
b. The value of i is 0
c. Finished
d. Compilation Error ( no ; after while condn);
e. Runtime Error
}}
35. Which of the following is the correct class declaration for Car.java. See to that
it is a case-sensitive system
int in;
in = inn
}}
int in;
in = inn;
}}
c. public class Car{
int in;
in = inn;
}}
d. import java.io.*;
int in;
in = inn;
}}
class Super{
String name;
Super(String s){
name =s ;
}}
class Sub extends Super{
String name;
Sub(String s){
name=s;
a. First Second
b. Second First
c. Compilation error
d. Runtime error stating same name found in Super as well as in the Sub
class
a. new Exception();
b. throw Exception();
c. throw new(new IOException());
d. throw new Exception(); // its actually throw new IOException();
e. throws new Exception();
OK
42. What is the output of the following program if method1() does not throw any
exception?
try{
method1();
System.out.println("First");
System.out.prinln("Second");
}finally{
System.out.println("Finally");
} System.out.println("Last");
43. What are the modifier which cannot be used for a local automatic variable
a. Applet
b. Panel
c. Component
d. Container
e. MenuItem // can be added only to a Menu
46. How to invoke the constructor from a constructor in the same class
class Super{
float x;
float y;
float z;
x = a;
y = b;
XXXX
z = c;
a. super(a,b);
b. Super(a,b);
c. this(a,b);
d. This(a,b);
a. private class C
b. new simpleinterface() { //Anonymous so v can use new
c. new complexinterface(x) {
d. new innerclasses() extends someotherclass {
e. new innerclasses extends someotherclass { //Not as we have given a name and
so v cannot use new
50. If a class member variable is initialized and the value is not be changed at all,
what is the modifier to be used during the declaration of the variable
a. const
b. fixed
c. public
d. static
e. final
51. What will happen if the following assignment is made, take the above into
account?
class Parent
Parent p;
Derived d1;
p = d1;
52. Which modifiers are to be used to obtain the lock on the object
a. public
b. private
c. static
d. synchornized
e. lock
a. import java.awt.*;
b. package local.util;
c. class NoExample{}
d. protected class SimpleExample
e. public static final double PI = 3.14;
String firstname;
String secondname;
Super(){}
firstname = f;
secondname = s;
}}
String firstname;
String secondname;
Sub(String f, String s){
firstname = f;
secondname = s;
}}
class Test{
}}
class Outer{
class Inner{
XXXX
a. new Inner();
b. Inner i = Outer.new Inner();
c. Outer.Inner i = new Outer().new Inner();
d. Inner i = Outer(new Inner());
Stack s1;
Stack s2;
new Example();
}
public Example() {
s1 = new Stack();
s2 = new Stack();
method1(s1,s2);
ms2.push(new Long(100));
ms1 = ms2;
a. %employee
b. $employee
c. employ-ee
d. employee1
e. _employee
59. Which of the following are true about the listener mathods in AWT? (C)