Questions
public class Dec26 { public static void main(String[] args) { short a1 = 6; new Dec26().go(a1); new Dec26().go(new Integer(7)); } void go(Short x) { System.out.print("S "); } void go(Long x) { System.out.print("L "); } void go(int x) { System.out.print("i "); } void go(Number n) { System.out.print("N "); } } What is the result?
- i L
- i N
- S L
- S N
- Compilation fails.
import java.util.Scanner; public class ScannerTest { public static void main(String[] args) { Scanner scanner = new Scanner("hello 1 2.00 false"); scanner.useDelimiter(" "); String str = scanner.next(); int anInt = scanner.nextInt(); float aFloat = scanner.nextFloat(); boolean booleanValue = scanner.nextBoolean(); System.out.println(str + ":" + anInt + ":" + aFloat + ":" + booleanValue); } } What is the output?
- The program will output 'hello:1:2.0:false'
- The program will throw Input Mismatch exception at the run-time
- The program will output nothing.
- The program will ouput ':1:2.0:false'
public class Gen
- Compile time Error at line 1
- Compile time Error at line 3
- Compile time Error at line 4
- Compile time Error at line 5
- Run Time Error
What will be printed out if you attempt to compile and run the following code? int i=9; switch (i) { default: System.out.println("default"); case 0: System.out.println("zero"); break; case 1: System.out.println("one"); case 2: System.out.println("two"); }
- default
- default, zero
- error default clause not defined
- no output displayed
Which of the following statements are true?
- Methods cannot be overridden to be more private
- static methods cannot be overloaded
- private methods cannot be overloaded
- An overloaded method cannot throw exceptions not checked in the base class
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]); } }
- myprog
- good
- morning
- Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2"
Which of the following is not keyword or reserved word in Java?
- if
- then
- goto
- while
- case
What will happen if you try to compile and run the following code? public class Q { public static void main(String argv[]){ int anar[]=new int[5]; System.out.println(anar[0]); } }
- Error: anar is referenced before it is initialized
- null
- 0
- 5
What will be output if you try to compile and run the following code, but there is no file called Hello.txt in the current directory? import java.io.*; public class Mine { public static void main(String argv[]){ Mine m=new Mine(); System.out.println(m.amethod()); } public int amethod() { try { FileInputStream dis=new FileInputStream("Hello.txt"); }catch (FileNotFoundException fne) { System.out.println("No such file found"); return -1; }catch(IOException ioe) { } finally{ System.out.println("Doing finally"); } return 0; } }
- No such file found
- No such file found ,-1
- No such file found, Doing finally, -1
- 0
What will happen if you attempt to compile and run the following code? class Base {} class Sub extends Base {} class Sub2 extends Base {} public class CEx{ public static void main(String argv[]){ Base b=new Base(); Sub s=(Sub) b; } }
- Compile and run without error
- Compile time Exception
- Runtime Exception
- None of the above
What is the result of the following operation? System.out.println(4 | 3);
- 6
- 0
- 1
- 7
You need to create a class that will store unique object elements. You do not need to sort these elements but they must be unique. What interface might be most suitable to meet this need?
- Set
- List
- Map
- Vector
Which of the following statements are true?
- At the root of the collection hierarchy is a class called Collection
- The collection interface contains a method called enumerator
- The interator method returns an instance of the Vector class
- The Set interface is designed for unique elements
There is a table called Employee having columns are empno, ename , job , deptno,grade and salary. Which of the following is a correct query to change all emp salary with salary<10000 to 1.5 times and grade to ‘Promo’
- Update Employee set salary = salary * 1.5 and grade=’Promo’ where salary < 10000;
- Update Employee set salary = salary * 1.5, grade=’Promo’ where salary < 10000;
- Update table Employee set salary = salary * 1.5, grade=’Promo’ where salary < 10000;
- Update table Employee set salary = salary * 1.5 and grade=’Promo’ where salary < 10000;
Which of the following is Data Definition Language?
- INSERT
- CREATE
- UPDATE
- DELETE
Which type of Statement can execute parameterized queries?
- PreparedStatement
- ParameterizedStatement
- ParameterizedStatement and CallableStatement
- All kinds of Statements (i.e. which implement a sub interface of Statement)
Which type of Statement can execute queries stored on db server?
- CallableStatement
- ParameterizedStatement
- ParameterizedStatement and CallableStatement
- All kinds of Statements (i.e. which implement a sub interface of Statement)
Which packages contain the JDBC classes?
- java.jdbc and javax.jdbc
- java.jdbc and java.jdbc.sql
- java.sql and javax.sql
- java.rdb and javax.rdb
Which of the following are true ?
- The executeUpdate method returns all the rows that were affected
- The executeUpdate method returns the no. of rows that were affected
- Depends , as there is more than one version of this method with different return types
- None of the above
Which of the following is false wrt Transactions ?
- A transaction is a set of sql statements
- Auto commit to be set off before Transaction
- Auto commit to be set off after transaction
- Commit permanently records to database all changes waiting with current Connection
- Rollback is used in case of any error to undo transaction