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 15 – 2024
Welcome to your Java Test - 15 - 2024
Name
Email
Phone
Q1. Given that your module named foo.bar contains the following two source files: src/foo.bar/f/b/Baz1.java and src/foo.bar/f/c/Caz1.java.
Which of the following options can be used to compile this module?
(Assume that all directory paths are relative to the current directory.)
You had to select 1 option(s)
None
Q2. What will happen on running the following program?
public class DatabaseWrapper
{
static String url = "jdbc://derby://localhost:1527//mydb";
static DatabaseWrapper getDatabase()
{
System.out.println("Getting DB");
return null;
}
public static void main(String[ ] args)
{
System.out.println( getDatabase().url );
}
}
You had to select 1 option(s)
It will print Getting DB and jdbc://derby://localhost:1527//mydb without throwing an exception.
It will throw a NullpointerException at Runtime.
It will print jdbc://derby://localhost:1527//mydb but will NOT print Getting DB.
It will print Getting DB and then throw a NullPointerException.
It will print nothing.
None
Q3. What can be inserted into the following code at //1 so that it will print "Oldboy"?
//imports not shown
class Movie{
static enum Genre {DRAMA, THRILLER, HORROR, ACTION };
private Genre genre;
private String name;
Movie(String name, Genre genre){
this.name = name; this.genre = genre;
}
//accessors not shown
}
public class FilteringStuff {
public static void main(String[] args) {
List movies = Arrays.asList(
new Movie("On the Waterfront", Movie.Genre.DRAMA),
new Movie("Psycho", Movie.Genre.THRILLER),
new Movie("Oldboy", Movie.Genre.THRILLER),
new Movie("Shining", Movie.Genre.HORROR)
);
Predicate horror = mov->mov.getGenre() == Movie.Genre.THRILLER;
Predicate name = mov->mov.getName().startsWith("O");
//1 INSERT CODE HERE
.forEach(mov->System.out.println(mov.getName()));
}
}
You had to select 1 option(s)
movies.stream().filter(horror, name)
movies.filter({horror, name})
movies.stream().filter({horror, name})
movies.stream().filter(horror).filter(name)
movies.filter(horror).filter(name)
None
Q4. What will be the result of compiling and running the following code?
class Base{
public short getValue(){ return 1; } //1
}
class Base2 extends Base{
public byte getValue(){ return 2; } //2
}
public class TestClass{
public static void main(String[] args){
Base b = new Base2();
System.out.println(b.getValue()); //3
}
}
You had to select 1 option(s)
It will print 1
It will print 2.
Compile time error at //1
Compile time error at //2
Compile time error at //3
None
Q5. Given :
You had to select 1 option(s)
It will throw an exception at runtime due to code at //1 because the syntax to invoke a stored procedure is incorrect.
It will fail to compile unless statements at //2 and //3 are replaced with: stmt.setObject(1, "Jane", java.sql.Types.STRING); //2
stmt.setObject(2, "Doe", java.sql.Types.STRING); //3
It will fail to compile unless stmt.setString and stmt.setDate are used at //2 and //3.
A row with values "Doe", "Jane" will be stored.
A row with values "Jane", "Doe" will be stored.
It will throw an SQL exception at //2 because of a mismatch in parameter name.
It will throw an SQLException at //4 because of a mismatch in parameter name.
It will throw an SQLException at //4 because of the wrong order of parameter names.
None
Q6. Given:
public class TestClass
{
public static void main(String[] args) throws IOException {
final Reader reader = new FileReader("aaa.a"); //1
try(reader){
reader.read(); //2
}finally{
reader.read(); //3
}
reader.read(); //4
}
}
Assuming that the fle named aaa.a does not exist, what will be the outcome?
You had to select 1 option(s)
An exception will be thrown at line marked //1.
An exception will be thrown at line marked //2.
An exception will be thrown at line marked //3.
An exception will be thrown at line marked //4.
It will fail to compile.
None
Q7. Which of the following statements will evaluate to true?
You had to select 1 option(s)
"String".replace('g','G') == "String".replace('g','G')
"String".replace('g','g') == new String("String").replace('g','g')
"String".replace('g','G')=="StrinG"
"String".replace('g','g')=="String"
None of these.
None
Q8. What will be the result of attempting to compile and run the following program?
class TestClass{
public static void main(String args[]){
var i = 0;
for (i=1 ; i<5 ; i++) continue; //(1)
for (i=0 ; ; i++) break; //(2)
for ( ; i<5?false:true ; ); //(3)
}
}
You had to select 1 option(s)
The code will compile without error and will terminate without problem when run.
The code will fail to compile, since the continue can't be used this way.
The code will fail to compile, since the break can't be used this way.
The code will fail to compile, since the for statement in line 2 is invalid.
The code will compile without error but will never terminate.
None
Q9. Given:
record Student(int id, String... subjects){
int rank;
public int getRank(){
return rank;
}
}
public class TestClass{
public static void main(String[] args) {
Student s = new Student(123, new String[]{"math", "science"});
System.out.println(s);
}
}
Which change(s) will enable the code to compile?
You had to select 1 option(s)
Replace record with void.
replace record with class.
Make the rank variable private.
Make the rank variable static.
Change int rank; to int rank = 0; and add a setter method for rank.
Change the type of subjects from String... to String[].
None
Q10. Given:
DoubleStream ds = DoubleStream.of(1.0, 2.0, 3.0);
//INSERT CODE HERE
ds.map(doubleF.apply(5.0)).forEach(System.out::println);
Which of the following statements can be inserted in the above code?
You had to select 1 option(s)
None
Q11. What will be the output of the following code snippet?
int a = 1;
int[] ia = new int[10];
int b = ia[a];
int c = b + a;
System.out.println(b = c);
You had to select 1 option(s)
0
1
2
true
false
None
Q12. A java source file contains the following code:
interface I {
int getI(int a, int b);
}
interface J{
int getJ(int a, int b, int c);
}
abstract class MyIJ implements J , I { }
class MyI{
int getI(int x, int y){ return x+y; }
}
interface K extends J{
int getJ(int a, int b, int c, int d);
}
Identify the correct statements:
You had to select 1 option(s)
It will fail to compile because of MyIJ
It will fail to compile because of MyIJ and K
It will fail to compile because of K
It will fail to compile because of MyI and K
It will fail to compile because of MyIJ, K, and MyI
It will compile without any error.
None
Q13. What would be the result of attempting to compile and run the following program?
class TestClass{
static TestClass ref;
String[] arguments;
public static void main(String args[]){
ref = new TestClass();
ref.func(args);
}
public void func(String[] args){
ref.arguments = args;
}
}
You had to select 1 option(s)
The program will fail to compile, since the static method main is trying to call the non-static method func.
The program will fail to compile, since the non-static method func cannot access the static member variable ref.
Non static methods can access static as well as non static methods of a class.
The program will fail to compile, since the argument args passed to the static method main cannot be passed on to the non-static method func.
The program will fail to compile, since method func is trying to assign to the non-static member variable 'arguments' through the static member variable ref.
The program will compile and run successfully.
None
Q14. What will the following program print?
class Test{
public static void main(String args[]){
int i=0, j=0;
X1: for(i = 0; i < 3; i++){
X2: for(j = 3; j > 0; j--){
if(i < j) continue X1;
else break X2;
}
}
System.out.println(i+" "+j);
}
}
You had to select 1 option(s)
0 3
0 2
3 0
3 3
2 2
None
Q15. What will the following code print when run?
public class TestClass {
public static void main(String[] args) throws Exception {
var sa = new String[]{"a", "b", "c"};
for(String s : sa){
if("b".equals(s)) continue;
System.out.println(s);
if("b".equals(s)) break;
System.out.println(s+" again");
}
}
}
You had to select 1 option(s)
a
a again
c
c again
a
a again
b
a
a again
b
b again
c
c again
None
Q16. What will be the output of the following program?
class Test
{
static int i1, i2, i3;
public static void main(String[] args)
{
try
{
test(i1 = 1, oops(i2=2), i3 = 3);
} catch (Exception e)
{
System.out.println(i1+" "+i2+" "+i3);
}
}
static int oops(int i) throws Exception
{
throw new Exception("oops");
}
static int test(int a, int b, int c) {
return a + b + c;
}
}
You had to select 1 option(s)
1 0 0
1 2 0
1 2 3
0 0 0
It will not compile.
None
Q17. Given the following declarations, identify which statements will return true:
Integer i1 = 1;
Integer i2 = new Integer(1);
int i3 = 1;
Byte b1 = 1;
Long g1 = 1L;
Double d = 1.0;
You had to select 2 option(s)
i1 == i2
i1 == i3
i1 == b1
i1.equals(i2)
i1.equals(g1)
i1.equals(b1)
d > 1L
Q18. You have a file named customers.dat in c:\company\records directory. You want to copy all the lines in this file to another file named clients.dat in the same directory and you have the following code to do it:
public static void writeData() {
Path p1 = Paths.get("c:\\company\\records\\customers.dat");
//LINE 20 - INSERT CODE HERE
try (
var br = new BufferedReader(new FileReader(p1.toFile()));
var bw = new BufferedWriter(new FileWriter(p2.toFile()))) {
String line = null;
while ((line = br.readLine()) != null) {
bw.write(line);
bw.newLine();
}
}catch(Exception e){
e.printStackTrace();
}
}
Which of the following options can be inserted independent of each other at //LINE 20 to make it work?
Assume that the current directory for the program when it runs is c:\code.
You had to select 2 option(s)
Path p2 = p1.resolveSibling("\\clients.dat");
Path p2 = p1.resolveSibling("clients.dat");
Path p2 = p1.relativize("clients.dat");
Path p2 = Paths.get("c:", p1.subpath(0, 2).toString(), "clients.dat");
Path p2 = Paths.get("c:", p1.subpath(1, 2).toString(), "clients.dat");
Q19. What will the following code print when run?
public class TestClass {
public static void m1() throws Exception{
throw new Exception("Exception from m1");
}
public static void m2() throws Exception{
try{
m1();
}catch(Exception e){
//Can't do much about this exception so rethrow it
throw e;
}finally{
throw new RuntimeException("Exception from finally");
}
}
public static void main(String[] args) {
try{
m2();
}catch(Exception e){
Throwable[] ta = e.getSuppressed();
for(Throwable t : ta) {
System.out.println(t.getMessage());
}
}
}
}
You had to select 1 option(s)
It will print Exception from m1
It will print Exception from finally
It will not print any thing.
It will print a stack trace for a NullPointerException.
None
Q20. Consider following classes:
//In File Other.java
package other;
public class Other { public static String hello = "Hello"; }
//In File Test.java
package testPackage;
import other.*;
class Test{
public static void main(String[] args){
String hello = "Hello", lo = "lo";
System.out.print((testPackage.Other.hello == hello) + " "); //line 1
System.out.print((other.Other.hello == hello) + " "); //line 2
System.out.print((hello == ("Hel"+"lo")) + " "); //line 3
System.out.print((hello == ("Hel"+lo)) + " "); //line 4
System.out.println(hello == ("Hel"+lo).intern()); //line 5
}
}
class Other { static String hello = "Hello"; }
What will be the output of running class Test?
You had to select 1 option(s)
false false true false true
false true true false true
true true true true true
true true true false true
None of the above.
None
Q21. Given:
Instant now = Instant.now();
Instant now2 = //INSERT CODE HERE
System.out.println(now2);
Which of the following options can be inserted in the above code without causing any compilation or runtime errors?
You had to select 1 option(s)
now.truncatedTo(ChronoUnit.DAYS);
now.truncatedTo(Period.DAYS);
now.truncatedTo(TemporalUnit.DAYS);
Period.ofDays(now);
None
Q22. Consider the code shown below:
public class TestClass{
public static int switchTest(int k){
var j = 1;
switch(k){
case 1: j++;
case 2: j++;
case 3: j++;
case 4: j++;
case 5: j++;
default : j++;
}
return j + k;
}
public static void main(String[] args){
System.out.println( switchTest(4) );
}
}
What will it print when compiled and run?
You had to select 1 option(s)
5
6
7
8
9
It will not compile.
None
Q23. What will the following class print ?
class Test{
public static void main(String[] args){
int[][] a = { { 00, 01 }, { 10, 11 } };
int i = 99;
try {
a[val()][i = 1]++;
} catch (Exception e) {
System.out.println( i+", "+a[1][1]);
}
}
static int val() throws Exception {
throw new Exception("unimplemented");
}
}
You had to select 1 option(s)
99 , 11
1 , 11
1 and an unknown value.
99 and an unknown value.
It will throw an exception at Run time.
None
Q24. Given:
class Course{
private String id;
private String name;
public Course(String id, String name){
this.id = id; this.name = name;
}
//accessors not shows
}
What will the following code print?
List cList = Arrays.asList(
new Course("803", "OCAJP 7"),
new Course("808", "OCAJP 8"),
new Course("809", "OCPJP 8")
);
cList.stream().filter(c->c.getName().indexOf("8")>-1)
.map(c->c.getId())
.collect(Collectors.joining("1Z0-"));
cList.stream().forEach(c->System.out.println(c.getId()));
You had to select 1 option(s)
803
808
809
803
1Z0-808
1Z0-809
1Z0-808
1Z0-809
It will throw an exception at run time.
It will not compile.
None
Q25. Given:
class StaticTest{
void m1(){
StaticTest.m2(); // 1
m4(); // 2
StaticTest.m3(); // 3
}
static void m2(){ } // 4
void m3(){
m1(); // 5
m2(); // 6
StaticTest.m1(); // 7
}
static void m4(){ }
}
Which of the lines will fail to compile?
You had to select 2 option(s)
1
2
3
4
5
6
7
Q26. What will the following code print when compiled and run?
List list1 = List.of("A", "B");
List list2 = List.copyOf(list1);
list1.add("C"); //1
list2.add("D"); //2
System.out.println(list1+" "+list2);
You had to select 1 option(s)
[A, B] [A, B]
[A, B, C] [A, B]
[A, B, C] [A, B, C, D]
[A, B, C, D] [A, B, C, D]
Line marked //1 will cause an exception at run time.
Both the lines marked //1 and //2 will cause an exception at run time.
None
Q27. Given:
public class TestClass {
static int val = 10;
public static int reduce(int val){
class Inner{
public int reduce(int mval){
return mval-val--;
}
}
val--;
return new Inner().reduce(val);
}
public static void main(String[] args) {
reduce(5);
System.out.println(val);
}
}
You had to select 1 option(s)
5
10
0
9
Compilation failure.
None
Q28. Given:
import java.util.*;
class Student{ }
public class TestClass {
var students = new ArrayList(); //1
public static void main(String[] args) {
var student = new Student(); //2
var allStudents = new ArrayList(); //3
allStudents.add(student); //4
for(var s : allStudents){ //5
System.out.println(s);
}
Student s2 = allStudents.get(0); //6
var var = "what?"; //7
}
}
Which lines will cause compilation error?
You had to select 2 option(s)
//1
//2
//3
//4
//5
//6
//7
Q29. Given:
List strList = Arrays.asList("a", "aa", "aaa");
Function f = x->x.length();
Consumer c = x->System.out.print("Len:"+x+" ");
Predicate p = x->"".equals(x);
strList.forEach( *INSERT CODE HERE* );
What can be inserted in the code above?
You had to select 1 option(s)
f
c
p
c and p
All of the above.
None of the above.
None
Q30. Consider the following code:
import java.io.*;
public class Test
{
public static void main(String[] args) throws Exception
{
var fw = new FileWriter("text.txt");
// fw.write("hello"); //1
fw.close();
}
}
Which of the following statements are correct?
You had to select 1 option(s)
It will throw an exception if text.txt does not exist.
It will create text.txt file in the filesystem if it does not exist.
It will not throw an exception if text.txt does not exist and it will not create a file either because nothing is being written to the file.
It will throw an exception if //1 is uncommented and if text.txt does not exist.
It will throw an exception if text.txt already exists.
None
Q31. Which of these expressions will return true?
You had to select 4 option(s)
Q32. Identify correct statements about the following code:
You had to select 1 option(s)
It will always print _ab
It will always print either _ab or _ba
It will print either _ab or _a_b
It will print any of the following:
_ab, _ba, _a_b,_b_a
None
Q33. Given:
interface Carnivore{
default int calories(List food){
return food.size()*100;
}
int eat(List foods);
}
class Tiger implements Carnivore{
public int eat(List foods){
System.out.println("Eating "+foods);
return foods.size()*200;
}
}
public class TestClass {
public static int size(List names){
return names.size()*2;
}
public static void process(List names, Carnivore c){
c.eat(names);
}
public static void main(String[] args) {
List fnames = Arrays.asList("a", "b", "c");
Tiger t = new Tiger();
INSERT CODE HERE
}
}
Which of the following options can be inserted independent of each other in the code above without any compilation error?
You had to select 3 option(s)
process(fnames, t::eat);
process(fnames, t::calories);
process(fnames, TestClass::size);
process(fnames, Carnivore::calories);
process(fnames, Tiger::eat);
Q34. Given:
public class SimpleLoop {
public static void main(String[] args) {
int i=0, j=10;
var count = 0;
while (i<j) {
i++;
j--;
count++;
}
System.out.println(i+" "+j+" "+count);
}
}
What is the result?
You had to select 1 option(s)
6 4 5
6 5 5
6 5 6
6 4 6
5 5 5
None
Q35. Consider that you are writing a set of classes related to a new Data Transmission Protocol and have created your own exception hierarchy derived from java.lang.Exception as follows:
nthu.trans.ChannelException
+-- enthu.trans.DataFloodingException
+-- enthu.trans.FrameCollisionException
(Both enthu.trans.DataFloodingException and enthu.trans.FrameCollisionException extend ChannelException)
You have a TransSocket class that has the following method:
long connect(String ipAddr) throws ChannelException
Now, you also want to write another "AdvancedTransSocket" class, derived from "TransSocket" which overrides the above mentioned method. Which of the following are valid declaration of the overriding method?
You had to select 2 option(s)
int connect(String ipAddr) throws DataFloodingException
int connect(String ipAddr) throws ChannelException
long connect(String ipAddr) throws FrameCollisionException
long connect(String ipAddr) throws Exception
long connect(String str)
Q36. As a part of an application, you have serialized and stored some objects of a class in the database. At another place in the same application, you deserialize those objects.
After a few months you determine that you need to add one new String field in the class.
Which of the following statements are correct regarding the above described situation?
You had to select 1 option(s)
The objects serialized earlier cannot be deserialized to the updated class objects.
Objects serialized earlier can be deserialized to the updated class objects by adding a new serialVersionUID field with a value of 0 to the updated class.
No special change is necessary in the updated class. Objects serialized earlier will be deserialized to the updated class objects but the newly added field will be null.
Old serialized objects can be deserialized only if the original class had explicitly defined a serialVersionUID field and if the updated class maintains the same value for that field.
It is possible to deserialize the older objects into the update class objects even if the original class did not explicitly define the serialVersionUID field.
None
Q37. What would be the result of trying to compile and run the following program?
public class Test{
int[] ia = new int[1];
Object oA[] = new Object[1];
boolean bool;
public static void main(String args[]){
var test = new Test();
System.out.println(test.ia[0] + " " + test.oA[0]+" "+test.bool);
}
}
You had to select 1 option(s)
The program will fail to compile, because of uninitialized variable 'bool'.
The program will throw a java.lang.NullPointerException when run.
The program will print "0 null false".
The program will print "0 null true".
The program will print null and false but will print junk value for ia[0].
None
Q38. You have created a module named mycompany.smartschool packaged in smartschool.jar. This module uses a third party non-modular java library packaged as utils.jar.
How will you execute your module's main class named mycompany.smartschool.Main?
(Assume that the jar files are located in the current directory.)
You had to select 1 option(s)
java --module-path smartschool.jar;utils.jar
--module mycompany.smartschool/mycompany.smartschool.Main
java -classpath utils.jar --module-path smartschool.jar
--module mycompany.smartschool/mycompany.smartschool.Main
java -cp utils.jar;smartschool.jar --module mycompany.smartschool/mycompany.smartschool.Main
java -classpath utils.jar --module-jar smartschool.jar
-main-class mycompany.smartschool/mycompany.smartschool.Main
None
Q39. Given:
public class Student {
private String name;
private int marks;
public Student(String name, int marks){
this.name = name;
this.marks = marks;
}
public String toString(){
return name+":"+marks;
}
//getters and setters not shown
}
What can be inserted in the code below so that it will print:
{20=[S1:20, S3:20], 30=[S3:30]}
List ls = Arrays.asList(new Student("S1", 20),
new Student("S3", 30), new Student("S3", 20) );
//INSERT CODE HERE
System.out.println(grouping);
You had to select 1 option(s)
None
Q40. A developer has written the following code snippet:
Console c = System.console(); //1
String line = c.readLine("Please enter your name:"); //2
System.out.println("Hello, "+line); //3
Which of the following statements are true about this code if it is run in the background by a scheduler?
You had to select 1 option(s)
Line //1 will throw IOException
Line //1 will throw NullPointerException.
Line //2 will throw IOException.
Line //2 will throw NullPointerException.
Line //3 will print Hello, null.
None
Q41. Which statements regarding the following code are correct?
class A extends Thread
{
public void run()
{
System.out.println("Starting loop");
try{
Thread.sleep(10000); //1 sleep for 10 secs
}catch(Exception e){ e.printStackTrace(); }
System.out.println("Ending loop");
}
}
public class TestClass
{
public static void main(String args[]) throws Exception
{
A a = new A();
a.start();
Thread.sleep(1000);
a.interrupt();
}
}
You had to select 2 option(s)
This will not compile.
It will run and MAY end without throwing any exception.
It will run and will ALWAYS end with an InterruptedException stack trace on the command line.
It will run and will end without an InterruptedException if //1 is replaced with while(!isInterrupted()) { };
None of these.
Q42. Given that the file test.txt is accessible and contains multiple lines, which of the following code fragments will correctly print all the lines from the file?
You had to select 2 option(s)
Q43. Which of the following is/are valid instantiations and initializations of a multi dimensional array?
You had to select 2 option(s)
var array2D = { { 0, 1, 2, 4}, {5, 6}};
int[][][] array3D = {{0, 1}, {2, 3}, {4, 5}};
int[] array2D[] = new int [2] [2];
array2D[0] [0] = 1;
array2D[0] [1] = 2;
array2D[1] [0] = 3;
int[][] array2D = new int[][]{0, 1};
int[] arr = {1, 2};
int[][] arr2 = {arr, {1, 2}, arr};
int[][][] arr3 = {arr2};
int[][] array2D = new int[][] { { 0, 1, 2, 4} {5, 6}};
Q44. Consider the following code:
import java.util.*;
import java.text.*;
public class TestClass
{
public static void main(String[] args) throws Exception
{
double amount = 53000.35;
Locale jp = new Locale("jp", "JP");
//1 create formatter here.
System.out.println( formatter.format(amount) );
}
}
How will you create formatter using a factory at //1 so that the output is in Japanese Currency format?
You had to select 2 option(s)
NumberFormat formatter = NumberFormat.getCurrencyFormatter(jp);
NumberFormat formatter = new DecimalFormat(jp);
Format formatter = NumberFormat.getCurrencyInstance(jp);
NumberFormat formatter = DecimalFormat.getCurrencyInstance(jp);
NumberFormat formatter = NumberFormat.getInstance(jp);
NumberFormat formatter = new DecimalFormat("#.00");
Q46. Given:
public class TestClass
{
public static void main(String args[])
{
A ab = new B();
A ac = new C();
if( ac instanceof B b1){
b1.b();
if(b1 instanceof C c1){
c1.c();
}
}else{
ac.a();
}
}
}
class A {
void a(){ System.out.println("a"); }
}
class B extends A {
void b(){ System.out.println("b"); }
}
class C extends B {
void c(){ System.out.println("c"); }
}
What will be the output?
You had to select 1 option(s)
a
b
b
c
b
a
Compilation failure
None
Q46. Which of the following are true regarding overloading of a method?
You had to select 1 option(s)
An overloading method must have a different parameter list and same return type as that of the overloaded method.
If there is another method with the same name but with a different number of arguments in a class then that method can be called as overloaded.
If there is another method with the same name and same number and type of arguments but with a different return type in a class then that method can be called as overloaded.
An overloaded method means a method with the same name and same number and type of arguments exists in the super class and sub class.
None
Q47. What will the following code print?
IntStream is = IntStream.range(1, 6);
IntStream is2 = is.takeWhile(x-> x%2==0);
is2.forEach(System.out::print);
You had to select 1 option(s)
2
24
246
It will not print anything.
None
Q48. Given:
String INPUT_FILE = "c:\\temp\\src\\foo.bar\\module-info.java";
Assuming the file exists, which of the following options will print the contents of the file?
You had to select 2 option(s)
Q49. What will the following method print?
public static void iCanDoThis(){
int x = 2;
int y = ~x; //LINE 2
int z = x ^ y; //LINE 3
boolean flag = x z++; //LINE 4
if(flag) {
flag = x > y && x > --z; //LINE 6
}
if(z>-1){ //LINE 8
--z;
} else z++;
System.out.println(flag+" "+z); //LINE 11
}
You had to select 1 option(s)
true 0
false -1
false 0
true -1
None
Q50. Given the following code:
enum Title
{
MR("Mr. "), MRS("Mrs. "), MS("Ms. ");
private String title;
private Title(String s){
title = s;
}
public String format(String first, String last){
return title+" "+first+" "+last;
}
}
//INSERT CODE HERE
Identify valid code snippets ..
(Assume that Title is accessible wherever required.)
You had to select 4 option(s)
class TestClass{
void someMethod()
{
System.out.println(Title.format("Rob", "Miller"));
}
}
class TestClass{
void someMethod()
{
System.out.println(Title.MR.format("Rob", "Miller"));
}
}
class TestClass{
void someMethod()
{
System.out.println(MR.format("Rob", "Miller"));
}
}
enum Title2 extends Title
{
DR("Dr. ");
}
class TestClass{
void someMethod()
{
Title.DR dr = new Title.DR("Dr. ");
}
}
enum Title2
{
DR;
private Title t;
}
enum Title2
{
DR;
private Title t = Title.MR;
}
enum Title2
{
DR;
private Title t = Title.MR;
public String format(String s){ return t.format(s, s); };
}
Q51. What will the following code print when compiled and run?
Collection col = new HashSet();
col.add(1);
var list1 = List.of(col); //1
col.add(2); //2
var list2 = List.copyOf(col); //3
System.out.println(list1+", "+list2);
You had to select 1 option(s)
It will not compile.
Exception at run time at line marked //1.
Exception at run time at line marked //2.
Exception at run time at line marked //3.
[1, 2], [1, 2]
[1], [1, 2]
[[1, 2]], [1, 2]
None
Q52. Which of the following are valid at line 1?
public class X{
//line 1: insert code here.
}
You had to select 2 option(s)
var s;
String s = 'asdf';
String s = 'a';
String s = this.toString();
String s = asdf;
String s;
var al;
al = new ArrayList<>();
Q53. Which of the following declarations is equivalent to var b = 10>11;.
You had to select 2 option(s)
bool b = false;
var b = false;
var b = false|true;
bool b = (10<11);
boolean b = false;
Q54. Given:
module foo.filter{
requires api;
provides api.Filter with foo.DoNothingFilter;
}
Assuming that api.Filter is an interface with just a single method List filter(List l), which of the following is a valid implementation of foo.DoNothingFilter class?
You had to select 1 option(s)
None
Q55. What will the following code print?
enum AccountType{
CHECKING("Checking account"), SAVINGS("Savings account"),
FD("Fixed Deposit");
private String desc;
AccountType(String desc){
this.desc = desc;
}
@Override
public String toString(){
return "Acct type:"+super.toString();
}
}
public class TestClass {
public static void main(String[] args) {
var at = AccountType.valueOf("FD");
System.out.println(at.ordinal()+" "+at);
}
}
You had to select 1 option(s)
3 Acct type:FD
3 Acct type:Fixed Deposit
3 FD
2 Acct type:FD
2 FD
An exception will be thrown at run time
None
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