Skip to content
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Java Test 16 – 2024
Welcome to your Java Test - 16 - 2024
Name
Email
Phone
Q1. What is the result of compiling and running the following program?
public class Learner {
public static void main(String[] args) {
var dataArr = new String[4];
dataArr[1] = "Bill";
dataArr[2] = "Steve";
dataArr[3] = "Larry";
try{
for(String data : dataArr){
System.out.print(data+" ");
}
}catch(Exception e){
System.out.println(e.getClass());
}
}
}
You had to select 1 option(s)
Bill Steve Larry null
Bill Steve Larry class java.lang.NullPointerException
class java.lang.Exception Bill Steve Larry
Bill Steve Larry class java.lang.Exception
null Bill Steve Larry
None
Q2. Given:
Path p1 = Paths.get("c:\\temp\\test1.txt");
Path p2 = Paths.get("c:\\temp\\test2.txt");
Which of the following code fragments moves the file test1.txt to test2.txt, even if test2.txt exists?
Answered Incorrectly
You had to select 2 option(s)
Files.move(p1, p2);
Files.move(p1, p2, StandardCopyOption.REPLACE_EXISTING);
try(Files.move(p1, p2)){
}
try(Files.copy(p1, p2, StandardCopyOption.REPLACE_EXISTING)){
Files.delete(p1);
}
Files.copy(p1, p2, StandardCopyOption.REPLACE_EXISTING);
Files.delete(p1);
Q3. What will be the result of compilation and execution of the following code ?
IntStream is1 = IntStream.range(0, 5); //1
OptionalDouble x = is1.average(); //2
System.out.println(x); //3
You had to select 1 option(s)
It will print 2.5
It will print 2.0
It will print OptionalDouble[2.0]
It will print OptionalDouble[3.0]
It will print 2.0 if line at //2 is replaced with double x = is1.average();
It will print 2.5 if line at //2 is replaced with double x = is1.average();
None
Q4. What will the following code print when run?
class A {
}
class AA extends A {
}
public class TestClass {
public static void main(String[] args) throws Exception {
A a = new A();
AA aa = new AA();
a = aa;
System.out.println("a = "+a.getClass());
System.out.println("aa = "+aa.getClass());
}
}
You had to select 1 option(s)
It will not compile.
It will throw ClassCastException at runtime.
a = class AA
aa = class AA
a = class A
aa = class AA
None
Q5. Given:
public static void createFile(String name) throws Exception{
try (
OutputStream os = new FileOutputStream(name); ) {
//INSERT CODE HERE
//flush and close the streams that are open
}
}
Which of the following combinations of the lines of code and their outcome when inserted above, are correct?
You had to select 2 option(s)
DataOutputStream dos = new DataOutputStream(os);
dos.write(1);
A file of size 4 bytes will be created.
os.write(1);
A file of size 1 byte will be created.
BufferedOutputStream bos = new BufferedOutputStream(os);
DataOutputStream dos = new DataOutputStream(bos);
dos.write(1);
A file of size 1 byte will be created.
os.writeInt(1);
A file of size 4 bytes will be created.
Q6. Consider the following program :
class Test{
public static void main(String[] args){
short s = 10; // 1
char c = s; // 2
s = c; // 3
}
}
Identify the correct statements.
You had to select 2 option(s)
Line 3 is not valid.
Line 2 is not valid.
It will compile because both short and char can hold 10.
None of the lines 1, 2 and 3 is valid.
Q7. What will be the result of attempting to compile and run the following program?
public class TestClass{
public static void main(String args[ ] ){
String s = "hello";
StringBuilder sb = new StringBuilder( "hello" );
sb.reverse();
s.reverse();
if( s == sb.toString() ) System.out.println( "Equal" );
else System.out.println( "Not Equal" );
}
}
You had to select 1 option(s)
Compilation error.
It will print 'Equal'.
It will print 'Not Equal'.
Runtime error.
None of the above.
None
Q8. Consider the following program:
import java.util.*;
public class TestClass
{
static String[] sa = { "a", "aa", "aaa", "aaaa" };
static
{
Arrays.sort(sa);
}
public static void main(String[] args)
{
String search = "";
if(args.length != 0) search = args[0];
System.out.println(Arrays.binarySearch(sa, search));
}
}
What are all possible values this program can print when run?
You had to select 1 option(s)
Any number from -5 to 5.
Any number from -5 to 5 except -1.
Any number from -5 to 3.
Any number from -5 to 3 except -1.
One of a, aa, aaa, or aaaa.
One of a, aa, aaa, aaaa, or null.
None
Q9. Given the following code:
class M { }
class N{
private M m = new M();
public void makeItNull(M pM){
pM = null;
}
public void makeThisNull(){
makeItNull(m);
}
public static void main(String[] args){
N n = new N();
n.makeThisNull();
}
}
Which of the following statements are correct?
You had to select 1 option(s)
There are no instances of M to be garbage collected till the program ends.
A call to n.makeThisNull() marks the private instance of M for garbage collection.
Setting pM = null; in makeItNull(), marks the private instance of M for garbage collection.
private members of a class become eligible for garbage collection only when the instance of the class itself becomes eligible for garbage collection.
None
Q10. Given:
public class FunWithArgs {
public static void main(String[][] args) {
System.out.println(args[0][1]);
}
public static void main(String[] args) {
var fwa = new FunWithArgs();
String[][] newargs = {args};
fwa.main(newargs);
}
}
The above program is compiled with the command line:
javac FunWithArgs.java
and then run with:
java FunWithArgs a b c
What will be the output?
You had to select 1 option(s)
It will not compile.
It will throw ArrayIndexOutOfBoundsException at run time.
It will print b
It will print null
None
Q11. Identify the correct statements about the following code:
import java.util.*;
class Person {
private String name;
public Person(String name) { this.name = name; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String toString() { return name; }
}
class Helper {
public void helpPeople(Queue people, Queue helped) {
do {
Person p = (Person) people.poll();
System.out.println("Helped : " + p + " ");
helped.offer(p.getName());
} while (!people.isEmpty());
}
public static void main(String[] args) {
Queue q = new LinkedList();
q.offer(new Person("Pope"));
q.offer(new Person("John"));
Queue helpedQ = new LinkedList();
Helper h = new Helper();
h.helpPeople(q, helpedQ);
}
}
You had to select 2 option(s)
It will print :
Helped : Pope
Helped : John
It will compile with a warning.
It will throw an exception at runtime.
It will compile without warning but will throw an exception at runtime.
It will print :
Helped : John
Helped : Pope
It will print : Helped : John
It will print : Helped : Pope
Q12. Consider the following code:
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class MyCache {
private CopyOnWriteArrayList cal = new CopyOnWriteArrayList();
public void addData(List list){
cal.addAll(list);
}
public int getCacheSize(){
return cal.size();
}
}
Given that one thread calls the addData method on an instance of the above class with a List containing 10 Strings and another thread calls the getCacheSize method on the same instance at the same time, which of the following options are correct?
(Assume that no other calls have been made on the MyCache instance.)
You had to select 1 option(s)
The getCacheSize call may return any value between 0 and 10.
The getCacheSize call may return either 0 or 10.
The call to getCacheSize will be blocked until the call to addData finishes.
One of the threads may get a ConcurrentModificationException.
None
Q13. Given:
sealed class Automobile permits Car, Bus{
}
final class Car extends Automobile{
}
final class Bus extends Automobile{
}
What can be inserted in the following method code?
public static Automobile getSomething(){
final int x = 1;
return switch(x){
case 0 -> new Car();
INSERT CODE HERE
};
}
You had to select 2 option(s)
Q14. What can be inserted in the following code so that it will print exactly 2345 when compiled and run?
public class FlowTest {
static int[] data = {1, 2, 3, 4, 5};
public static void main(String[] args) {
for (var i : data) {
if (i < 2) {
//insert code1 here
}
System.out.print(i);
if (i == 3) {
//insert code2 here
}
}
}
}
You had to select 2 option(s)
break;
and
//nothing is required
continue;
and
//nothing is required
continue;
and
continue;
break;
and
continue;
break;
and
break;
Q15. What will the following code print when compiled and run?
BiPredicate bip = (s, i)-> s.length()>i; //1
BiFunction bif = (s, i)-> { //2
if(bip.test(s, i)){ //3
return s.substring(0, i);
}
else return s;
};
String str = bif.apply("hello world", 5); //4
System.out.println(str);
You had to select 1 option(s)
hello
compilation failure at //1
compilation failure at //2
compilation failure at //3
compilation failure at //4
None
Q16. Given the following classes and declarations, which of these statements about //1 and //2 are true?
class A{
private int i = 10;
public void f(){}
public void g(){}
}
class B extends A{
public int i = 20;
public void g(){}
}
public class C{
A a = new A();//1
A b = new B();//2
}
You had to select 1 option(s)
System.out.println(b.i); will print 10.
The statement b.f( ); will cause compile time error.
System.out.println(b.i); will print 20
All of the above are correct.
None of the above statements is correct.
None
Q17. What will be the output when the following class is compiled and run?
class ScopeTest{
static int x = 5;
public static void main(String[] args){
int x = ( x=3 ) * 4; // 1
System.out.println(x);
}
}
You had to select 1 option(s)
It will not compile because line //1 cannot be parsed correctly.
It will not compile because x is used before initialization.
It will not compile because there is an ambiguous reference to x.
It will print 12.
It will print 3 .
None
Q18. Given:
public class TestClass {
static int count = 0;
public static void main(String[] args) throws Exception{
ExecutorService es = Executors.newFixedThreadPool(5);
for(int i=0; i<5; i++){
es.submit( () ->
{
for(int j=0; j<5000; j++){
TestClass.count++;
}
}
);
}
es.awaitTermination(10, TimeUnit.SECONDS);
es.shutdownNow();
System.out.println(count);
}
}
Identify correct statement(s) about the above code.
You had to select 2 option(s)
The count variable is thread safe.
The count variable should be declared volatile to make it thread safe.
The main method should be declared synchronized to make it thread safe.
The code should increment the count variable inside a synchronized block and print it inside a synchronized block that synchronizes on a single common object to make it thread safe.
The count variable should be declared synchronized to make it thread safe.
The code should use AtomicInteger instead of int for count variable to make it thread safe.
Q19. What will the following code print?
var a = new int[]{ 1, 2, 3, 4, 5};
var b = new int[]{ 1, 2, 3, 4, 5, 3};
var c = new int[]{ 1, 2, 3, 4, 5, 6};
int x = Arrays.compare(a, c);
int y = Arrays.compare(b, c);
System.out.println(x+" "+y);
You had to select 1 option(s)
-1 -1
1 1
-1 -3
1 3
None
Q20. Given:
String sentence1 = "Carpe diem. Seize the day, boys. Make your lives extraordinary.";
String sentence2 = "Frankly, my dear, I don't give a damn!";
String sentence3 = "Do I look like I give a damn?";
List sentences = Arrays.asList(sentence1, sentence2, sentence3);
Which of the following options will create a stream containing all the words in the three sentences without repetition?
You had to select 1 option(s)
None
Q21. Given:
List l1 = Arrays.asList("a", "b");
List l2 = Arrays.asList("1", "2");
Which of the following lines of code will print the following output?
a
b
1
2
You had to select 1 option(s)
None
Q22. Consider the following code in which searchBook() method has an inner class.
public class BookStore
{
private static final int taxId = 300000;
private String name;
public String searchBook( final String criteria )
{
int count = 0;
int sum = 0;
sum++;
class Enumerator
{
String iterate( int k)
{
//line 1
return "";
}
// lots of code.....
}
// lots of code.....
return "";
}
}
Which variables are accessible at line 1?
You had to select 5 option(s)
taxId
name
criteria
count
k
sum
Q23. Given that Daylight Savings Time ends on Nov 1 at 2 AM in US/Eastern time zone, what will the following code print -
LocalDateTime ld = LocalDateTime.of(2022, Month.OCTOBER, 31, 10, 0);
ZonedDateTime date = ZonedDateTime.of(ld, ZoneId.of("US/Eastern"));
date = date.plus(Duration.ofDays(1));
System.out.println(date);
date = ZonedDateTime.of(ld, ZoneId.of("US/Eastern"));
date = date.plus(Period.ofDays(1));
System.out.println(date);
You had to select 1 option(s)
2022-11-01T09:00-05:00[US/Eastern]
2022-11-01T09:00-05:00[US/Eastern]
2022-11-01T09:00-05:00[US/Eastern]
2022-11-01T10:00-05:00[US/Eastern]
2022-11-01T10:00-05:00[US/Eastern]
2022-11-01T09:00-05:00[US/Eastern]
2022-11-01T10:00-05:00[US/Eastern]
2022-11-01T10:00-05:00[US/Eastern]
None
Q24. What is wrong with the following code?
class MyException extends Exception {}
public class TestClass{
public static void main(String[] args){
TestClass tc = new TestClass();
try{
tc.m1();
}
catch (MyException e){
tc.m1();
}
finally{
tc.m2();
}
}
public void m1() throws MyException{
throw new MyException();
}
public void m2() throws RuntimeException{
throw new NullPointerException();
}
}
You had to select 1 option(s)
It will not compile because you cannot throw an exception in finally block.
It will not compile because you cannot throw an exception in catch block.
It will not compile because NullPointerException cannot be created this way.
It will not compile because of unhandled exception.
It will compile but will throw an exception when run.
None
Q25. Which statement regarding the following code is correct?
class A{
public int i = 10;
private int j = 20;
}
class B extends A{
private int i = 30; //1
public int k = 40;
}
class C extends B{
}
public class TestClass{
public static void main(String args[]){
C c = new C();
System.out.println(c.i); //2
System.out.println(c.j); //3
System.out.println(c.k);
}
}
You had to select 1 option(s)
The code will print 10 and 40 if //3 is commented out.
The code will print 40 if //2 and //3 are commented out.
The code will not compile because of //1.
The code will compile if the line marked //2 is commented out.
None of these.
None
Q26. Given:
You are trying to initialize the STOCK table and for that you need to insert one row for each of the ticker value in the tickers array. Each row has to be initialized with the same values except the ID and TICKER columns, which are different for each row. The ID column is defined as AUTO_INCREMENT and so you need to pass only 0 for this column.
Which of the following code snippets would you use?
You had to select 1 option(s)
None
Q27. Given:
class MyException extends Exception {
private final int code;
public MyException(int code, Throwable actualEx){
super(actualEx);
this.code = code;
}
public MyException(int code, String message, Throwable actualEx){
super(message, actualEx);//1
this.code = code;
}
public String getMessage(){
return String.format("Exception - Code=%d, Msg=%s, OrigMsg=%s", code,
super.getMessage(), this.getCause().getMessage()); //2
}
}
public class TestClass {
public static void main(String[] args) {
try{
throw new MyException(new IOException("NOT FOUND")); //3
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
What is the result?
You had to select 1 option(s)
Compilation failure at //3
It will print:
Exception - Code=0, Msg=null, OrigMsg=NOT FOUND
It will print:
Exception - Code=0, Msg=NOT FOUND, OrigMsg=null
It will print:
Exception - Code=0, Msg=, OrigMsg=null
None
Q28. Given the following two files in /user/home directory:
In file messages.properties:
message=hi {0}, thanks {1}
In file messages_fr_FR.properties:
message=salut {0}, merci {1}
and the following class in /user/home directory:
public class TestClass
{
public static void main(String[] args) {
//INSERT CODE HERE
System.out.println(message);
}
}
Which of the following options when inserted in TestClass will print salut Amy, merci Adams?
Answered Incorrectly
You had to select 2 option(s)
ResourceBundle msg = ResourceBundle.getBundle("/user/home/messages",
new Locale("fr", "FR"));
Object[] names = { "Amy", "Adams" };
String message = MessageFormat.format(msg.getString("message") , names);
ResourceBundle msg = ResourceBundle.getBundle("messages.messages", Locale.FRANCE);
Object[] names = { "Amy", "Adams" };
String message = MessageFormat.format(msg.getString("message") , names);
ResourceBundle msg = ResourceBundle.getBundle("messages", new Locale("fr", "FR"));
Object[] names = { "Amy", "Adams" };
String message = MessageFormat.format(msg.getString("message") , names);
Locale.setDefault(Locale.FRANCE);
ResourceBundle msg = ResourceBundle.getBundle("messages");
String message = MessageFormat.format(msg.getString("message") , "Amy", "Adams");
Q29. Given:
public static void reader(String fileName1) throws Exception{
try (var fr = new FileReader(fileName1);) {
int charRead = 0;
while ((charRead = fr.read()) != -1) {
System.out.println("Read char " + charRead);
}
}
}
What can be done to the above code to make it read Strings instead of chars?
You had to select 1 option(s)
Chain fr to a StringReader and use its readString method.
Use fr.readString instead of fr.read.
Chain fr to a BufferedReader use its readLine method
Chain fr to a DataReader and use its readLine method.
None
Q30. Given:
List letters = Arrays.asList("j", "a", "v","a");
Which of the following code snippets will print JAVA?
You had to select 3 option(s)
Q31. Which of these array declarations and instantiations are legal?
You had to select 4 option(s)
int[ ] a[ ] = new int [5][4] ;
int a[ ][ ] = new int [5][4] ;
int a[ ][ ] = new int [ ][4] ;
int[ ] a[ ] = new int[4][ ] ;
int[ ][ ] a = new int[5][4] ;
var[ ] a[ ] = new int [5][4] ;
var[ ][ ] a = new int [5][4] ;
Q32. Given the following class, which of the given blocks can be inserted at line 1 without errors?
public class InitClass{
private static int loop = 15 ;
static final int INTERVAL = 10 ;
boolean flag ;
//line 1
}
You had to select 4 option(s)
static {System.out.println("Static"); }
static { loop = 1; }
static { loop += INTERVAL; }
static { INTERVAL = 10; }
{ flag = true; loop = 0; }
var flag2 = flag ;
Q33. Assume the following declarations:
class A{ }
class B extends A{ }
class C extends B{ }
class X{
B getB(){ return new B(); }
}
class Y extends X{
//method declaration here
}
Which of the following methods can be inserted in class Y?
You had to select 2 option(s)
public C getB(){ return new B(); }
protected B getB(){ return new C(); }
C getB(){ return new C(); }
A getB(){ return new A(); }
Q34. What will the following code print?
void crazyLoop(){
var c = 0;
JACK: while (c < 8){
JILL: System.out.println(c);
if (c > 3) break JILL; else c++;
}
}
You had to select 1 option(s)
It will not compile.
It will throw an exception at runtime.
It will print numbers from 0 to 8
It will print numbers from 0 to 3
It will print numbers from 0 to 4
None
Q35. Consider the following classes :
interface I{
}
class A implements I{
}
class B extends A {
}
class C extends B{
}
And the following declarations:
A a = new A();
B b = new B();
Identify options that will compile and run without error.
You had to select 1 option(s)
a = (B)(I)b;
b = (B)(I) a;
a = (I) b;
I i = (C) a;
None
Q36. Given:
class TestClass{
public static void main(String[] args) throws IOException {
final InputStream fis = new FileInputStream("c:\\temp\\test.txt");
long l = 0;
try(fis){
l = fis.read();//1
}finally{
l = fis.read();//2
}
l = fis.read();//3
System.out.println(l);//4
}
}
Assuming that c:\\temp\\test.txt is readable, what will be the output?
You had to select 1 option(s)
Compilation failure.
Exception at //1.
Exception at //2.
Exception at //3.
Value of the first byte in the file will be printed.
Value of the second byte in the file will be printed.
None
Q37. Given:
Map hm = new ConcurrentHashMap();
hm.put(null, "asdf"); //1
hm.put("aaa", null); //2
hm = new HashMap();
hm.put(null, "asdf"); //3
hm.put("aaa", null); //4
List list = new ArrayList();
list.add(null); //5
list.add(null); //6
list = new CopyOnWriteArrayList();
list.add(null); //7
Which of the above lines will throw NullPointerException?
(Assume that each of the put and add calls are executed as if they are wrapped inside a try/catch block i.e. an exception thrown at //1 will not prevent the execution of //2.)
You had to select 2 option(s)
//1
//2
//3
//4
//5
//6
//7
Q38. Given:
class M {
static Object obj = null;
public M(String val){ obj = val; }
}
class N{
private M m = new M("hello");
public static void main(String[] args){
N n = new N();
n = null;
System.gc();
System.out.println(M.obj);
}
}
Assuming that System.gc() does its job, what will be printed?
You had to select 1 option(s)
null
It will throw a NullPointerException at run time.
hello
It will thrown an IllegalAccessException at run time.
It will not compile.
None
Q39. Given the following class:
public class Food{ // LINE 1
String name;
int caloriesPerServing;
public Food(String name, int calories){
this.name = name; this.caloriesPerServing = calories;
}
//accessors not shown
//LINE 2
}
This class is used in an application as follows -
ArrayList al = new ArrayList();
//code that adds Food objects to al not shown
Collections.sort(al);
What changes must be done to Food class so that the call to Collections.sort(al) will work as expected?
You had to select 2 option(s)
Q40. Given:
List primes = Arrays.asList(2, 3, 5, 7, 11, 13, 17); //1
Stream primeStream = primes.stream(); //2
Predicate test1 = k->k<10; //3
long count1 = primeStream.filter(test1).count();//4
Predicate test2 = k->k>10; //5
long count2 = primeStream.filter(test2).count(); //6
System.out.println(count1+" "+count2); //7
Identify correct statements.
You had to select 1 option(s)
It will print 4 3 if line at //6 is replaced with:
long count2 = primeStream.reset().filter(test2).count(); //6
It will print 4 3 if types of count1 and count2 are changed to int.
It will print 4 3 if line //4 and //6 are replaced with:
long count1 = IntStream.of(primes).filter(test1).count();//4
and
long count2 = IntStream.of(primes).filter(test2).count();//6
It will print 34 or 43 if lines 4 to 7 are replaced with:
primeStream.collect(Collectors.partitioningBy(test1, Collectors.counting()))
.values().forEach(System.out::print);
None
Q41. Consider the following classes :
class A{
public static void sM1() { System.out.println("In base static"); }
}
class B extends A{
Line 1 --> // public static void sM1() { System.out.println("In sub static"); }
Line 2 --> // public void sM1() { System.out.println("In sub non-static"); }
}
Which of the following statements are true?
You had to select 2 option(s)
class B will not compile if line 1 is uncommented.
class B will not compile if line 2 is uncommented.
class B will not compile if line 1 and 2 are both uncommented.
Only the second option is correct.
Only the third option is correct.
Q42. Given:
class MyProcessor{
int value;
public MyProcessor(){ value = 10; }
public MyProcessor(int value){
this.value = value;
}
public void process(){
System.out.println("Processing "+value);
}
}
Which of the following code snippets will print Processing 10?
You had to select 2 option(s)
Q42. Which of the following are valid JDBC URLs?
You had to select 1 option(s)
jdbc:derby://localhost:1527/sample
//jdbc://derby://localhost:1527/sample
http://jdbc:mysql:localhost/sample
https://mysql.com:3306/sample
None
Q43. Which of these for statements are valid when present in a method?
1. for (var i=5; i=0; i--) { }
2. var j=5;
for(int i=0, j+=5; i<j ; i++) { j--; }
3. int i, j;
for (j=10; i<j; j--) { i += 2; }
4. var i=10;
for ( ; i>0 ; i--) { }
5. for (int i=0, j=10; i<j; i++, --j) {;}
6. for (var i=0, j=10; i<j; i++, --j) {;}
You had to select 1 option(s)
1, 2
3, 4
1, 5
4, 5
5
4, 5, 6
None
Q45. Consider the following interface definition:
public interface ConstTest{
public int A = 1; //1
int B = 1;Â Â Â Â Â //2
static int C = 1;Â //3
final int D = 1; //4
public static int E = 1; //5
public final int F = 1;Â //6
static final int G = 1;Â Â //7
public static final int H = 1; //8
}
Which line(s) will cause a compilation error?
Answered Incorrectly
You had to select 1 option(s)
1
2
3
5
6
7
8
None of them will cause any error.
None
Q46. What will the following code print when run?
class A{
String value = "test";
A(String val){
this.value = val;
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
new A("new test").print();
}
}
You had to select 1 option(s)
test
new test
It will not compile.
It will throw an exception at run time.
None
Q47. Consider the following code:
class OuterWorld
{
public InnerPeace i = new InnerPeace("none"); //1
class InnerPeace
{
private String reason = "none";
InnerPeace(String reason){ this.reason = reason; }
}
public static void main(String[] args){
var ip = new InnerPeace("yoga"); //2
var out = new OuterWorld();
System.out.println(out.i.reason); //3
}
}
Identify correct statements about the above code.
You had to select 2 option(s)
Compilation error at //1
Compilation error at //2
Compilation error at //3
code at //2 can be compiled if InnerPeace definition changed to:
private static class InnerPeace ...
code at //2 can be compiled if InnerPeace definition is moved to a separate InnerPeace.java file without impacting other parts of the code.
Q48. Consider these two interfaces:
interface I1
{
void m1() throws java.io.IOException;
}
interface I2
{
void m1() throws java.io.FileNotFoundException;
}
Which of the following are valid method declarations for a class that says it implements I1 and I2 ?
You had to select 1 option(s)
Both, public void m1() throws FileNotFoundException; and public void m1() throws IOException;
public void m1() throws FileNotFoundException
The class cannot implement both the interfaces as they have conflicting methods.
public void m1() throws Exception;
None of the above.
None
Q49. Identify the correct statements about the following code:
import java.util.*;
class Person {
private static int count = 0;
private String id = "0"; private String interest;
public Person(String interest){ this.interest = interest; this.id = "" + ++count; }
public String getInterest(){ return interest; }
public void setInterest(String interest){ this.interest = interest; }
public String toString(){ return id; }
}
public class StudyGroup
{
String name = "MATH";
TreeSet set = new TreeSet();
public void add(Person p) {
if(name.equals(p.getInterest())) set.add(p);
}
public static void main(String[] args) {
StudyGroup mathGroup = new StudyGroup();
mathGroup.add(new Person("MATH"));
System.out.println("A");
mathGroup.add(new Person("MATH"));
System.out.println("B");
System.out.println(mathGroup.set);
}
}
You had to select 1 option(s)
It will print : A, B, and then the contents of mathGroup.set.
It will compile with a warning.
It will NOT throw an exception at runtime.
It will compile without warning but will throw an exception at runtime.
It will only print : A
It will print : A and B.
None
Q50. Consider the following code:
//INSERT CODE HERE
a[0][0] = 1;
a[0][1] = 2;
a[1][0] = 3;
a[1][1] = 4;
a[1][2] = 5;
a[1][3] = 6;
What can be inserted independently in the above code so that it will compile and run without any error or exception?
You had to select 2 option(s)
int[][] a = new int[2][];
int[][] a = new int[2][4];
int[][] a = new int[4][2];
int[][] a = new int[2][];
a[0] = new int[2];
a[1] = new int[4];
int[][] a = new int[4][];
a[0] = new int[2];
a[1] = new int[2];
Time's up
Time is Up!
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Contact Us
(510) 550 - 7200
39141 Civic Center Dr, Suite 201, Fremont, CA 94539, US