Java Objective Questions

Java (I) Which of the following will produce a value of 22 if x=22.9:
Ceil(x) Round(x) Rint(x) Abs(x) C
Java (I) If m and n are int type variables, what will be the result of the expression
'm % n' when m = -14 and n = -3?



4 2 -2 -4 C
Java (I) Consider the following statements:
int x = 10, y = 15;
x = ((x < y) ? (y + x) : (y - x);
What will be the value of x after executing these statements?





25 15 5 Error can't be executed. A
Java (I) Which of the following will produce a value of 10 if x = 9.7?




floor(x) abs(x) rint(x) round(x) D
Java (I) Which of the following control expressions are valid for an if statement?




an integer expression a Boolean expression either A or B Neither A or B B
Java (I) Consider the following class definition.
Class Student extends String
{
}
What happens when we try to compile this class?





Will not compile because class body is not defined Will not compile because class is not declared public Will compile successfully. Will not compile because String is abstract D
Java (I) What is wrong in the following class definitions?
abstract class print
{
abstract show();
}
class Display extends print
{
}



Nothing is wrong Wrong Method show() should have a return type
Wrong Methods show() is not implemented in Display Wrong Display does not contain any members. C
Java (I) What is error in the following class definitions?
abstract class xy
{
abstract sum(int x, int y) {}
}


class header is not define properly constructor is no defined method is not defined properly no error
C
Java (I) Consider the following class definitions:
class maths
{
student student1;
}
class student
{
String name;
}
This code represents:




an 'is a' relationship a 'has a' relationship both neither B
Java (I) Which key word can protect a class in package from accessibility by the classes outside the package?


private protected final
don't use any keyword at all(make it default)
D
Java (I) We would like to make a member of a class visible in all subclasses regardless of what package they are in. Which one of the following keywords would achieve this?




private protected public private protected D
Java (I) The use of protected keyword to a member in a class will restrict its visibility as follows:





Visibility only in the class and its subclasses in the same package. Visibility only inside the same package. Visibility in all classes in the same package and subclasses in other packages. Visibility only in the class where it is declared. C
Java (I) Which of the following are not keywords?



NULL Implements Protected None of the above A
Java (I) Which of the following are keywords?





integer default Boolean Object B
Java (I) Which of the following keywords are used to control access to a class member?




default protected interface None of the above B
Java (I) The keywords reserved but not used in the initial version of Java re:





Synchronized Boolean union goto D
Java (I) A package is a collection of




classes interface editing tools classes and interfaces D
Java (I) Which of the following statements are true?




An abstract class may not have any final methods? A final class may not have any abstracts methods. Transient variables must be static. all of the above B
Java (I) The concept of multiple inheritance is implemented in Java by




extending two or more classes extending one class and implementing one or more interfaces all the above B
Java (I) Which of the following statements are valid array declarations?




int number(); float average[]; double[] marks; counter int[]; B
Java (I) Consider the following code
int number[]=new int[5];



After execution of this statement, which of the following are true? number[5] is undefined number[0] is undefined B
Java (I) Which of the following classes are available in the java.lang package?

Random Stack String Buffer Vector A
Java (I) Which of the following are the wrapper classes?


Random Vector Byte all of the above C
Java (I) Which of the following methods belong to the String class?
length() compareTo() substring() all of the them D
Java (I) Given the code
String s = new String("abc");
Which of the following calls are valid?
s.toUpperCase() s.append("xyz") s.setCharAt(1,'A') all of the above A
Java (I) The methods wait() and noify() are defined in





java.lang.Thread java.lang.Runnable java.lang.Object java.lang.ThreadGroup C
Java (I) When we invoke repaint () for a Component, the AWT invokes the method:



draw() update() show() paint() B
Java (I) What does the following line of code do?
TextField text=new TextField(10);



Creates text object that can hold 10 rows of text. Creates text object that can hold 10 columns of text. Creates the object text and initializes it with the value 10. The code is illegal.
B
Java (I) Which of the following applet tags is legal to embed an applet class named Test into a web page?





code=test.class width=200 height=100> width=200 height=100> D
Java (I) Which of the following methods can be used to draw the outline of a square?

fillRect() drawLine() drawString() all of the above B
Java (I) Which of the following methods can be used to change the size of a




size() *
resize()
component dimension() setSize() size() C
Java (I) Which of the following methods can be used to remove a component from the display?





remove() desappear() hide() move() C
Java (I) The setBackground() method is part of the class





Applet Component Container Object B
Java (I) When we implement the Runnable interface, we must define the method
start() init() runnable() run() D
Java (I) Which of the following string can be used as mode string for creating a RandomAccessFile object?





"rw" "wr" "0" ''w'' A
Java (I) DataInput is




An abstract class defined is java.io. A class we can use to read primitive data types. An interface that defines methods to open files. An interface that defines methods to read primitive data types. D
Java (I) Which of the following statements are true?
UTF characters are all 24 bits. Reader class has methods that can read integers and floats. Unicode characters are all 16 bits. all of the above C
Java (I) Which are the valid ways to create DataInputStream streams?
new DataInputStream(new File("in.dat")); new DataInputStream(new FileInputStream("in.dat")); new DataInputStream("in.dat");
new DataInputStream("in.data","r"); B
Java (I) Which exception is thrown by the read() method of InputStream class?





IOException FileNotFoundException ReadException None of the above A
Java (I) In the code below, what data types the variable x can have?
byte b1 = 5; byte b2 = 10; x = b1 * b2; int short D
Java (I) If you want to assign a value of 99 to the variable year, then which of the following lines can be used within an tags?
number=getParameter(99) C
Java (I) What is java -g used for?


Using the jdb tool Executing a class with optimization turned off To provided information about deprecated methods Non of the above B
Java (I) With javadoc, which of the following denotes a javadoc comment?




//# /* /** //** C
Java (I) Give file is a file object, which of the following are legal statements to create a new file.

file.create(); FileOutputStream fos=new FileOutputStream(file); FileInputStream fis=new FileInputStream(file); all of the above B
Java (I) Which javadoc tag is used to denote a comment for methods parameters?

@method @parameter @argument @param D
Java (I) Which of the following command lines options generates documentation for all classes and methods?
-protected -public -private -encoding C
Java (I) Which of the following represent legal flow control statements?

break; break(); continue(inner); all of the above A
Java (I) Consider the following code snippet:
try
{
int x=0;
int y=50/x;
System.out.println("Division by zero");
}
catch(ArithmeticException e)
{
System.out.println("catch block");
}

What will be the output?




Error. Won't compile Division by zero Catch block Division by zero catch block C
Java (I) Which of the following represent legal flow control statements?





break(); continue(inner); return; exit(); C
Java (I) The name of a Java program file must match the name of the class with the extension Java.


True False A
Java (I) Two methods cannot have the same name in Java.


True False B
Java (I) The modulus operator (%) can be used only with Integer operands.

True False
B
Java (I) Declarations can appear anywhere in the body of a Java method.

True False
A
Java (I) All the bitwise operators have the same level of precedence in Java.


True False A
Java (I) When X is a positive number the operations x>> 2 and x>>>2 both produce the same result.


True False A
Java (I) If a=10 and b= 15, then the statement x =(a>b)?a:b; assigns the value 15 to x.


True False A
Java (I)
In evaluating a logical expression of type 'Boolean expression 1&& Boolean expression 2', both the Boolean expressions are not always evaluated.


True False A
Java (I) In evaluating the expression (x == y&& a

True False B
Java (I) The default case is always required in the switch selection structure.


True False B
Java (I)
The break statement is required in the default case of a switch selection structure.


True False B
Java (I) The expression (x == y && a

True False B
Java (I) A variable declared inside the for loop control can not be referenced out side the loop.


True False A
Java (I) Java always provides a default constructor to a class.



True False B
Java (I) When present, package must be the first no comment statement in the file.


True False A
Java (I) The import statement is always the first no comment statement in a Java program files.


True False B
Java (I) Objects are passed to a method by use of call-by-reference.


True False A
Java (I) It is perfectly legal to refer to any instance variable inside of a static method.


True False B
Java (I) When we implement an interface method, it should be declared as public.


True False A
Java (I) We can over load methods with differences only in their return type.


True False B
Java (I) It is an error to have a method with the same signature in both the super class and its subclass.


True False B
Java (I) A constructor must always invoke its supper class constructor in its first statement.


True False B
Java (I) Any class may be inherited by another class in the same package.


True False B
Java (I) Any method in a supper class can be over ridden in its subclass.

True False B
Java (I) One the features of is that an array can store many different types of values.


True False B
Java (I) An individual array element that is passed to a method and modified in that method will contain the modified value when the called method completes execution.


True False B
Java (I) Members of a class specified as private are accessible only to the methods of the class.


True False A
Java (I) A method declared as static can not access non-static class members.


True False A
Java (I) A static class method can be invoked by simply using the name of the method alone.


True False

B
Java (I) It is an error if a class with one or more abstract methods is not explicitly declared abstract.


True False

A
Java (I) It is perfectly legal to assign a subclass object to a supper class reference.


True False

A
Java (I) Every method of a final in class is implicitly final.


True False

A
Java (I) All methods in an abstract class must be declared abstract.


True False

B
Java (I) When the string objects are compared with ==, the result is true If the strings contain the same values.


True False

B
Java (I) A string object can not be modified after it is created.


True False

A
Java (I) The length of a string object 's1' can be obtained using the expression s1.length.


True False

B
Java (I) A catch can have comma-separated multiple arguments.


True False

B
Java (I) It is an error to catch the same type of exception in two different catch blocks associated with a particular try block.


True False

A
Java (I) Throwing an exception always causes program termination.


True False

B
Java (I) Every call to wait has a corresponding call to notify that will eventually end the wafting.


True False

A
Java (I) Declaring a method synchronized guarantees that the deadlock cannot occur.


True False

A
Java (I) The programmer must explicitly create the system .in and system .out objects.


True False

B
Java (I) To delete a file, we can use an instance of class file.


True False

A
Java (I) A panel can not be added to another panel.


True False

B
Java (I) Frames and applets cannot be used together in the same program.


True False

B
Java (I) A final class may not have any abstract method.


True False

A
Java (I) A class may be both abstract and final.


True False

B
Java (I) A thread can make second thread ineligible for execution by calling the suspend (-) method on second thread.


True False

A
Java (I)
A Java monitor must either extend thread class or implement Runnable interface.


True False

B
Java (I) The check box group class is a subclass of the component class.


True False

B
Java (I) If a=10 and b= 15, then the statement x =(a>b)?a:b; assigns the value 15 to x.



True False

A
Java (I) Java is fully object oriented programme. true false

A
Java (II) For all insert, update, delete, query operations on a database, ResultSet object creation is mandatory.

True. False.

B
Java (II) forName() is a static factory method


True False

A
Java (II) DriverManager.getConnection("jdbc:odbc:dsn_name") method does not depend on the class.forName(...) method.


True. False.

B
Java (II) Connection, Statement are interfaces and ResultSet is a class.


True. False.

B
Java (II) JdbcOdbcDriver is an object of Object class

True False

B
Java (II) class.forName(...) creates an instance of java ODBC driver


True False

A
Java (II) Submit button always fires doPost(...)

True False


B
Java (II) We can add more than one class(es) at the time of compilation Java Beans.


True. False.

A
Java (II) In RMI before running the client program we must start RMI Registry.


True. False.

A
Java (II) An EJB is a server-side component that encapsulates the business logic of an application


True False

A
Java (II) Message-Driven beans act as a listener for the Java Message Service API, processing messages synchronously


True False

B
Java (II) In RMI we invoke client method from remote server


True False

B
Java (II) In order to connect to a database through java program we must create _______-




Connection, Statement, ResultSet Connection, ResultSet Statement, ResultSet Connection, Statement D
Java (II) executeUpdate(------------) returns ___________



Nothing Returns a ResultSet object Returns an integer value to show the no. of updated rows None of the above. C
Java (II) executeUpdate automatically updates data because___________




auto commit is on, by default It performs a hidden commit statement as well Does not commit None of the above. A
Java (II) In a single Servlet class we can use____________




doGet(...) method only doPost(...) method only doGet(...) method and doPost(...) method both at a time. Either 'a' or 'b' C
Java (II) putValue(...) method takes _____________________-



Two arguments of object type First one is of a character type and second one is of an object type First one is of an object type and second one is of a character type None of the above.
A
Java (II) Servlet has ___________



init method doGet(------) method All of the above methods.
C
Java (II) Servlet can have ___________



get method and post method get method or post method Either of the above
C
Java (II) JSP files creates ________________




html files html files and java files java files and class files None of the above. C
Java (II) A JSP file can be stored_________________




With the extension .jsp in servlets folder of the jws With the extension .html in public_html folder of the jws With the extension .jsp in public_html folder of the jws None of the above. C
Java (II) The name of the RMI compiler is ___________




rmicom rmic jrmi none of the above B
Java (II) EJBs can be of the following type(s)




None of the above
Entity Bean Session Bean Message-driven bean All of the above D

2 comments:

MANOJ KUMAR said...

Good collection! Also, please visit http://www.gitarani.com/classified.htm?classifiedTypeId=5 to know more technical related stuff.

Manojkumar Ramshekar said...

very helpful good collection