SCJP 6 Free Mock Exam

Question 1 of 25 [Declarations, Initialization and Scoping]
Code : Parent.java class Parent {
void aMethod(String args){
}
}
class Child extends Parent {
}
}
Which of the following methods are valid at Child class?
Choice 1void aMethod(int number) {}
Choice 2String aMethod(String args) {}
Choice 3private void aMethod(String args) {}
Choice 4protected void aMethod(String args) throws IndexOutOfBoundsException {}
Question 2 of 25 [Declarations, Initialization and Scoping]
Code : Test.java

class Test {
public static void main(String... arg) {
System.out.print("Inside main"+arg);
}
public static void main(String[] arg) {
main(arg);
}
}
What will be the output of compiling and running the Test class with "Java Tiger" as the command line argument?
Choice 1Compiles and runs without any output.
Choice 2Exception at runtime.
Choice 3Inside MainJava Tiger
Choice 4Inside MainJava
Choice 5Compiler Error
Question 3 of 25 [Declarations, Initialization and Scoping]
Code : Inner.java

class Inner {
public static void main(String[] args) {
Inner inner = new Inner();
inner.new Outer().innerMethod();
}
final int num = 2399;
class Outer {
int num=9932;
void innerMethod() {
System.out.println( -------------);
}
}
}
Which of the following code snippets can be inserted on the-------------to print 2399?
Choice 1Inner.this.num
Choice 2super.num
Choice 3num
Choice 4Outer.Inner.num
Choice 5Inner.Outer.num
Choice 6None of the above
Question 4 of 25 [Declarations, Initialization and Scoping]
Code : Customer.java class Customer {
static String accountNumber = "";
public Customer() { }
static String getAccountNumber() {
return accountNumber; }
}
class CreditCardCustomer extends Customer {
public String getAccountNumber() throws RuntimeException {
return accountNumber;
}
}
What will happen when you compile and run the Customer class?
Choice 1Compilation error
Choice 2Runtime error
Choice 3Compiles and runs without any error
Choice 4getAccountNumber method of CreditCardCustomer objects throws RuntimeException
Question 5 of 25 [Flow Control]
Which of the following statements are TRUE about checked exception?
Choice 1Represents the defects in the program.
Choice 2Are subclasses of exception.
Choice 3Are subclasses of RuntimeException, and are usually implemented using IllegalArgumentException, NullPointerException, or IllegalStateException.
Choice 4Represent invalid conditions in areas outside the immediate control of the program
Question 6 of 25 [Flow Control]
Code : Test.java
1. class Test {
2. public static void main(String [] args) {
3. new Test().testMethod();
4. }
5.
6. void testMethod() {
7. try {
8. System.out.println("Java");
9. return;
10. }
11. finally {
12. System.exit(0);
13. System.out.println(" Tiger");
14. }
15. }
16. }
Which of the following statement about the given code is TRUE?
Choice 1Compiler error at line 13.
Choice 2Compile time error. Catch block is missing.
Choice 3Prints "Java"
Choice 4Prints "Java Tiger "
Choice 5Prints "Tiger"
Question 7 of 25 [Flow Control]
Code : Sample.java class Sample {
public static void main(String args[]) {
int arg = 10;
switch (arg) {
case 0: System.out.print("Java ");
case 10: System.out.print("JSP ");
case 20: System.out.print("EJB ");
case 30: System.out.print("JMS ");
case 40: System.out.print("JNDI "); break;
default: System.out.print("None ");
}
}
}
What will happen when you compile and run the Sample class?
Choice 1JSP
Choice 2JSP None
Choice 3JSP EJB JMS JNDI
Choice 4JSP EJB JMS
Question 8 of 25 [Flow Control]
Code : // Bank.java
package bank;
public class Bank{
String getBankBranchName() {
return "Head Office";
}
}
// BankBranch.java
package bankBranch;
import bank.*;
public class BankBranch extends Bank {
String bankBranchName=null;
String getBankBranchName(){
super.getBankBranchName();
}
}
What will happen when you compile and run the Bank and BankBranch classes?
Choice 1Bank class will compile and BankBranch will not
Choice 2Both classes will not compile
Choice 3BankBranch class will compile and Bank will not
Choice 4Both compiles without any error
Question 9 of 25 [API Contents]
Code: Test.java import java.io.*;
class Test{
public static void main(String[] args) throws IOException {
Writer w=new BufferedWriter(new FileWriter("FILE.TXT"));
}
}
What will happen when you try to compile and run the following code without FILE.TXT?
Choice 1Compiler error
Choice 2FileNotFoundException will be thrown
Choice 3IOException will be thrown
Choice 4The code compiles and runs without any error
Question 10 of 25 [API Contents]
Locale.getAvailableLocales method must return an array that contains at least a Locale instance equal to Locale.US.
Choice 1True
Choice 2False
Question 11 of 25 [API Contents]
The following method names are present in both String and Pattern classes.
Choice 1split
Choice 2concat
Choice 3compile
Choice 4length
Choice 5matches
Question 12 of 25 [API Contents]
Which of the following statements are TRUE about File class?
Choice 1File(String) constructor creates a new File instance by converting the given pathname string into an abstract pathname. If the given string is the empty string, then the result is the empty abstract pathname.
Choice 2File(String) constructor creates a new File instance by converting the given pathname string into an abstract pathname. If the given string is the empty string, then it will throw FileNotFoundException.
Choice 3File(String) constructor creates a new File instance by converting the given pathname string into an abstract pathname. If the given string is the empty string, then it will throw IOException.
Choice 4File class is used to create directories.
Question 13 of 25 [Concurrency]
Which of the following statements are TRUE?
Choice 1Interrupted method stops the current thread temporarily.
Choice 2Interrupted method always interrupts the thread and returns true.
Choice 3Interrupted method returns true if the current thread has been interrupted; false otherwise.
Choice 4Interrupted method clears the interrupted status of the thread.
Question 14 of 25 [Concurrency]
Which of the following method by invoking on an object causes all threads waiting for that object's lock to wake up?
Choice 1notify()
Choice 2run()
Choice 3create()
Choice 4notifyAll()
Question 15 of 25 [OO Concepts]
Code : class Y { }
class X extends Y {
X() {
System.out.print("Java");
super();
}
}
The above mentioned code compiles successfully.
Choice 1True
Choice 2False
Question 16 of 25 [OO Concepts]
Code : Test.java 1. public class Test {
2. public static void main(String [] args) {
3. new Test().main("");
4. }
5.
6. public void main(String...arg) {
7. System.out.println("Hello");
8. }
9.
10. }
What will happen when you compile and run the Test class?
Choice 1The code compiles successfully and run with "Hello" as the output
Choice 2Changing main(String…arg) at line 6. to Main(String arg) will compile successfully
Choice 3The code fails to compile because of duplicate methods.
Choice 4Compile time error at line no.5 about the null argument.
Question 17 of 25 [OO Concepts]
Code : CreditCardCustomer.java class Customer {
String customerID;
private String getCustomerID() {
return customerID;
}
}
class CreditCardCustomer extends Customer {
public static void main(String[] argv) {
Customer brad = new CreditCardCustomer();
brad.customerID="12122";
System.out.print(brad.getCustomerID());
}
String getCustomerID() {
return customerID;
}
}
What will happen when you attempt to compile and run the above code?
Choice 1Compiler error
Choice 212122
Choice 3Runtime error
Choice 4null
Question 18 of 25 [OO Concepts]
Code : BankBranch.java class Bank {
String bankName;
public String getBranchName() {
return bankName;
}
}
public class BankBranch extends Bank {
public static void main(String[] argv)
{ }
public String getBranchName() throws Exception {
return bankName;
}
}
What will happen when you attempt to compile and run the above code?
Choice 1Compiles and runs without any error
Choice 2Runtime error
Choice 3Compile time error
Choice 4null
Question 19 of 25 [Collections / Generics]
Which of the following methods are defined in the Arrays class?
Choice 1asList
Choice 2deepEquals
Choice 3sort
Choice 4binarySearch
Choice 5All of the above
Question 20 of 25 [Collections / Generics]
Which of the following statements are TRUE with respect to Set and Collection?
Choice 1A Set cannot contain repeated elements.
Choice 2The equals() method cannot be used to test whether two objects should be considered the same.
Choice 3The equals() method is used to test whether two objects should be considered the same.
Choice 4A Set can contain repeated elements.
Question 21 of 25 [Collections / Generics]
Code : PayRoll.java import java.util.*;
public class PayRoll {
public static void main(String[] args) {
Vector<String> employeeList = new Vector<String>();
Vector<Integer> employeeIdList = new Vector<Integer>();
Vector<Object> employeeProfileList = new Vector<Object>();
System.out.print(employeeList.getClass()== employeeIdList.getClass());
System.out.print(employeeList.equals(employeeProfileList));
System.out.print(employeeList.getClass()== employeeProfileList.getClass());
System.out.print(employeeIdList.equals(employeeProfileList));
}
}
What is the result of compiling and running the above code?
Choice 1Runtime error
Choice 2Compile error
Choice 3truefalsetruefalse
Choice 4falsefalsefalsetrue
Choice 5falsetruetruetrue
Choice 6truetruetruetrue
Question 22 of 25 [Collections / Generics]
Code : Student.java 1. public class Student {
2. public static void main(String[] args) {
3. Integer studentRollNo = 145;
4. Object num1 = new String("145");
5. Object num2 = studentRollNo;
6. studentRollNo = null;
7. Object num4 = num2.toString();
8.
9. System.out.println(num1.equals(num4));
10. }
11. }
What will happen when you attempt to compile and run the given code?
Choice 1Runtime error at line 11
Choice 2Compile time error at line 5
Choice 3Complie time error at line 7
Choice 4Runtime error at line 7
Choice 5Compiles and runs without any error and prints true
Question 23 of 25 [Collections / Generics]
Code : DeptList.java

import java.util.*;
public class DeptList {
public static void main(String[] args) {
ArrayList deptNoList=new ArrayList<Integer>();
deptNoList.add(0);
deptNoList.add(1);
deptNoList.add(5);
deptNoList.add(19);
deptNoList.add(101);
deptNoList.add(600);
for( ---- deptNo : deptNoList) {
System.out.print(deptNoList+" ");
if(deptNo.equals(5))
break;
}
}
}
Replace the --- with the correct choice to compile and run the code successfully.
Choice 1int
Choice 2String
Choice 3Integer
Choice 4Object
Choice 5Number
Question 24 of 25 [Fundamentals]
&, | always have a numeric operands.
Choice 1True
Choice 2False
Question 25 of 25 [Fundamentals]
Code : DeptList.java
package com.epl.test;
class Test {
public static void main(String[] args) {
System.out.println("Package");
}
}
Select the correct command to run the code.
Choice 1java -classpath /com/epl/test; com.epl.test.Test
Choice 2java com.epl.test.Test
Choice 3java com/epl/test/Test
Choice 4java com/epl/test/ com.epl.test.Test
Choice 5java Test