1) Given The Following Class Definition
1) Given The Following Class Definition
1) Given The Following Class Definition
Code:
class A {
protected int i;
A(int i) {
this.i = i;
}
}
Which of the following would be a valid inner class for this class?
a) class B { }
b) class B extends A { }
c) class B {
B() {
System.out.println("i = " + i);
}
}
d) class B {
class A {
}
}
e) class A {
}
Which of the following conditions are valid and will return true?
a. (f==g)
b. (g==d)
c. (f.equals(new Float(0.9F))
d. (f.equals(d))
e. (f.equals(g))
<details> <category> 1 <count> 5 <type> 0 <answer> CE <explain> none </details>
</question>
Code:
public class Test {
public static void main(String args[]) {
StringBuffer a = new StringBuffer("One");
StringBuffer b = new StringBuffer("Two");
Test.swap(a,b);
System.out.println("a is "+ a +"\nb is " + b);
}
Answer:
a. a is One
b is Two
b. a is One
b is One
c. a is One more
b is One more
d. a is One more
b is Two
e. a is One more
b is Two more
a) True
b) False
a) True
b) False
a) True
b) False
7) Abstract class cannot have final methods. True or False ?
a) True
b) False
a) True
b) False
9) A final class cannot have abstract methods. True or False ?
a) True
b) False
10) A sample question provided by Sun
What would be the result of attempting to compile and run the following piece of code?
What should you use to position a Button within an application Frame so that the size of the
Button is
NOT affected by the Frame size?
A.a FlowLayout
B.a GridLayout
C.the center area of a BorderLayout
D.the East or West area of a BorderLayout
E.the North or South area of a BorderLayout
What can contain objects that have a unique key field of String type, if it is required to retrieve
the
objects using that key field as an index?
A.Map
B.Set
C.List
D.Collection
E.Enumeration
A.NULL
B.sizeof
C.friend
D.extends
E.synchronized
Select all valid answers.
16) A sample question provided by Sun
Which code fragments would correctly identify the number of arguments passed via
command line to a
Java application, excluding the name of the class that is being invoked?
A.InputStream
B.OutputStream
C.File
D.RandomAccessFile
E.StreamTokenizer
1)
2) {
3) if (atest()) {
4) unsafe();
5) }
6) else {
7) safe();
8) }
9) }
Given a TextArea using a proportional pitch font and constructed like this:
Code:
public class Example {
int x, y;
public Example(int a) {
//lots of complex computation
x=a;
}
Short answer, like "one(a)" ,do not add the semicolon at the end,
“This(a)”
22) A sample question provided by Sun
A.sizeof
B.abstract
C.native
D.NULL
E.BOOLEAN
Which are correct class declarations? Assume in each case that the text constitutes the
entire contents of
a file called Fred.java on a system with a case-significant file system.
E.import java.awt.*;
public class Fred extends Object {
int x;
private Fred (int xval) {
x = xval;
}
}
A class design requires that a particular member variable must be accessible for direct
access by any
subclasses of this class, but otherwise not by classes which are not members of the same
package.
What should be done to achieve this?
A.an Applet
B.a Component
C.a Container
D.a Menu
E.a Panel