Java-Programming (Set 6)
Java-Programming (Set 6)
6 of 7 sets
501. Given the code String s = new String("abc"); Which of the following call is not
valid?
A. s.trim().
B. s.replace('a', 'A').
C. s.substring (3).
D. s.setCharAt (1,'A').
Answer:B
504. When we implement the Runnable interface, we must define the method
A. run().
B. start().
C. init().
D. main().
Answer:A
505. 15 & 29 =?
A. 44.
B. 14.
C. 13.
D. 12.
Answer:C
507. Consider the following code: int x, y, z;~~~y = 1;~~~z = 5;~~~x = 0 - (++y) +
z++;~~~after execution of this, what will be the values of x, y and z?
A. x = 4, y = 1, z = 5.
B. x = 3, y = 2, z = 6.
C. x = -7, y = 1, z = 5.
D. x = 4, y = 2, z = 6.
Answer:B
508. What will be the result of the expression: a % b when a & b is of type int and
their values~~~are a = 10 and b = 6?
A. 1.66.
B. 1.
C. 2.
D. 4.
Answer:D
510. The keywords reserved but used in the initial version of JAVA are:
A. union.
B. const.
C. inner.
D. goto.
Answer:A
513. Which of the following methods can be used to draw the outline of a square
within a JAVA.awt.Component object?
A. drawLine().
B. fillRect().
C. drawString().
D. drawPolygon().
Answer:A
515. Which of the following method can be used to change the size of a
JAVA.awt.Component object?
A. dimension().
B. setSize().
C. area().
D. size().
Answer:B
517. 27 | 8 = ?
A. 8.
B. 27.
C. 19.
D. 35.
Answer:B
518. What will be the result of the expression : a % b~~~when a and b are of type
int and their values are a = -17 and b = -6?
A. -5.
B. -23.
C. 0.
D. 5.
Answer:D
526. After the following code fragment, what is the value in a?~~~String s; int
a;~~~s = "Foolish boy."; a = s.indexOf("fool");
A. -1.
B. 0.
C. 4.
D. random value.
Answer:A
536. Given the following code fragment:~~~int A[];int i = 0;A = new int
A[4];~~~while (i < 4)~~~{~~~A[i] = 10;~~~i = i + 1;~~~}~~~What is the value of
A[3]?.
A. 0.
B. 3.
C. 10.
D. 9.
Answer:C
537. What is the value of k after the following code fragment?~~~int k = 0;~~~int n
= 12~~~while (k < n)~~~{~~~k = k + 1;~~~}
A. 0.
B. 11.
C. 12.
D. 10.
Answer:C
539. The modulus operator (%) in JAVA can be used only with variables of ______
type.
A. double & char.
B. int & double.
C. int.
D. double.
Answer:B
542. When Java source code is compiled, each individual class is put into its own
output file named after the class and using the ______ extension.
A. .h.
B. . java.
C. >java.
D. .class.
Answer:D
545. When you read your e-mail, you are viewing _________ data.
A. active.
B. passive.
C. active and passive.
D. active or passive.
Answer:B
550. Java support RMI. What does this RMI stands for?
A. Random Memory Interface.
B. Remote Method Invocation.
C. Random Method Invocation.
D. Remote Memory Interface.
Answer:B
551. _________ is a feature that allows one interface to be used for a general class
of actions.
A. Class.
B. Inheritance.
C. Polymorphism.
D. Interface.
Answer:C
553. The term _____________ refers to a class's direct ancestor or to any of its
ascendant.~~~classes.
A. sub class.
B. super class.
C. class hierarchy.
D. class instance.
Answer:B
554. A single-line comment begins with a ________ and ends at the end of the line.
A. / .
B. // .
C. /* .
D. **.
Answer:B
557. The new operator dynamically allocates ________ for an object and returns a
reference to it.
A. classes.
B. variables.
C. memory.
558. Method overloading is one of the way that Java supports ____________.
A. encapsulation.
B. class.
C. inheritence.
D. polymorphism.
Answer:D
560. Methods declared as static have several restrictions:~~~1) They can only call
other static methods.~~~2) They must only access static data.~~~3) They cannot
refer to this or super in any way~~~Which of these are true?
A. 1 and 2.
B. 1 and 3.
C. 2 and 3.
D. 1, 2 and 3.
Answer:D
562. The data or variables, defined within a class are called _______ variables.
A. object.
B. class.
563. In this example class_var = new classname ( ); the class name followed by
parentheses~~~specifies the _________ for the class.
A. destructor.
B. constructor.
C. variables.
D. memory.
Answer:B
566. You would use the ____ operator to create a single instance of a named class.
A. new.
B. dot.
C. equals.
D. <>.
Answer:A
567. Java's garbage collector runs as a ______ priority thread waiting for _______
priority threads to relinquish the processor. Choose the correct sequence.
568. What is the default thread at the time of starting the program?
A. Main Thread.
B. Thread Group.
C. Child Thread.
D. Thread Pool.
Answer:A
570. What are the part in executing a Java program and their purposes?
A. Java Compiler.
B. Java Interpreter.
C. Java Pre-processor.
D. Directive Pre-processor.
Answer:A
572. What are the constants defined by Byte, Short, Integer and Long? 1.
MAX_VALUE, 2.~~~MIN_VALUE 3. TYPE.
573. What is the unit for 1000 in the below statement? ob.sleep(1000)
A. Long milliseconds.
B. Double milliseconds.
C. Int milliseconds.
D. Float milliseconds.
Answer:A
574. 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);~~~}~~~}
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. Compiles but generates a compile time error.
Answer:B
578. What will happen when the class below is complied?~~~public class
Example~~~{~~~//char a = 'u000A';~~~}
A. Will complete successfully.
B. Will compile successfully but with a warning message.
C. Will not compile - complains on an invalid expression.
D. Will show a warning message.
Answer:A
581. Which of the function is used to convert String to Number in java program?
A. toNumber ().
B. conString().
C. valueOf() .
D. toString().
582. Interface methods can be declared with which the following modifiers?
A. public.
B. private.
C. synchronized.
D. native.
Answer:A
584. All the wrapper classes (Integer, Boolean, Float, Short, Long, Double and
Character).
A. are public.
B. are final.
C. are serializable.
D. are private.
Answer:D
586. Can you write a Java class that could be used both as an applet as well as an
application?
A. Yes
B. No
C. -