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 standard test 11 Code 1Z 829
Welcome to your Java Test - 11
Name
Email
Phone
1.
Question: 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?
Select 2 option(s)
var pw = new PrintWriter(os);
pw.write(1);
Size of the file depends on default character encoding.
os.write(99);
A file of size 1 byte will be created.
var bos = new BufferedOutputStream(os);
var pw = new PrintWriter(bos);
pw.print(99);
A file of size 1 byte will be created.
os.writeInt(99);
A file of size 4 bytes will be created.
var pw = new PrintWriter(os);
pw.writeInt(1);
A file of size 4 bytes will be created.
2.
Question: Given the following code:
List aList = List.of(40, 30, 20); //1
List bList = List.copyOf(aList); //2
bList.sort((Integer::compare)); //3
System.out.println( bList ); //4
aList.sort((Integer::compare)); //5
System.out.println( aList ); //6
Identify correct statement.
Select 1 option(s)
Line //2 will cause compilation failure.
Lines //3 and //5 will cause compilation failure.
Lines //3 and //5 will cause an java.lang.UnsupportedOperationException to be thrown at runtime.
Only line //3 will cause an java.lang.UnsupportedOperationException to be thrown at runtime.
Only line //5 will cause an java.lang.UnsupportedOperationException to be thrown at runtime.
There will be no compilation error or exception at runtime, but both the print statements will print unsorted values.
Line //3 will cause an java.lang.UnsupportedOperationException to be thrown at runtime.
Line //5 will not cause any exception at runtime.
Line //6 will print sorted values.
None
3.
Question: What will the following program print?
class LoopTest{
public static void main(String args[]) {
var counter = 0;
outer:
for (var i = 0; i < 3; i++) {
middle:
for (var j = 0; j < 3; j++) {
inner:
for (var k = 0; k < 3; k++) {
if (k - j > 0) {
break middle;
}
counter++;
}
}
}
System.out.println(counter);
}
}
Select 1 option(s)
2
3
6
7
9
None
4.
Question: What will the following code print when compiled and run?
public class TestClass{
public static void main(String[] args){
int[] arr = { 1, 2, 3, 4, 5, 6 };
int counter = 0;
for (var value : arr) {
if (counter >= 5) {
break;
} else {
continue;
}
if (value > 4) {
arr[counter] = value + 1;
}
counter++;
}
System.out.println(arr[counter]);
}
}
Select 1 option(s)
It will not compile.
It will throw an exception at run time.
5
6
7
8
None
5.
Question: What will be the output when the following code is compiled and run?
//in file Test.java
class E1 extends Exception{ }
class E2 extends E1 { }
class Test{
public static void main(String[] args){
try{
throw new E2();
}
catch(E1 e){
System.out.println("E1");
}
catch(Exception e){
System.out.println("E");
}
finally{
System.out.println("Finally");
}
}
}
Select 1 option(s)
It will not compile.
It will print E1 and Finally.
It will print E1, E and Finally.
It will print E and Finally.
It will print Finally.
None
6.
Question: Given the following code:
var raf = new RandomAccessFile("c:\\temp\\test.txt", "rwd");
raf.writeChars("hello");
raf.close();
Which of the following statements are correct?
(Assume that the code has appropriate security permissions.)
Select 1 option(s)
If the file test.txt does not exist, an attempt will be made to create it.
If the file test.txt does not exist, an exception will be thrown.
If the file test.txt exists, an exception will be thrown.
If the file test.txt exists, it will be overwritten and all the existing data will be lost.
If the file test.txt exists, the given characters will be appended to the end of the existing data.
None
7.
Question: What will the following code print when compiled and run?
var nameList = new ArrayList();
nameList.add("Ally");
nameList.add("Billy");
nameList.add("Cally");
nameList.add("Billy");
nameList.add("Ally");
var nameSet1 = new HashSet();
for(var name:nameList) nameSet1.add(name);
var nameSet2 = new HashSet(nameList);
System.out.println(nameList.size()+" "+nameSet1.size()+" "+nameSet2.size());
Select 1 option(s)
5 3 5
5 3 3
5 3 1
3 3 1
5 5 5
5 5 1
None
8.
Question: What will the following code print when compiled and run?
Select 1 option(s)
Compilation error at //1
Compilation error at //2
Compilation error at //3
Compilation error at //1 and //3
It will print WORLDhello
It will print WORLDHELLO
It will print HELLOWORLD
None
9.
Question: The following program will print
java.lang.ArithmeticException: / by zero
class Test{
public static void main(String[] args){
int d = 0;
try{
int i = 1 / (d* doIt());
} catch (Exception e){
System.out.println(e);
}
}
public static int doIt() throws Exception{
throw new Exception("Forget It");
}
}
Select 1 option(s)
True
False
None
10.
Question: Given that Book is a valid class with appropriate constructor and getTitle and getPrice methods that return a String and a Double respectively, what will the following code print?
List books = Arrays.asList(
new Book("Gone with the wind", 5.0),
new Book("Gone with the wind", 10.0),
new Book("Atlas Shrugged", 15.0)
);
books.stream().collect(Collectors.toMap((b->b.getTitle()), b->b.getPrice()))
.forEach((a, b)->System.out.println(a+" "+b));
Select 1 option(s)
Gone with the wind 5.0
Atlas Shrugged 15.0
Gone with the wind 10.0
Atlas Shrugged 15.0
Gone with the wind 5.0
Gone with the wind 10.0
Atlas Shrugged 15.0
It will throw an exception at run time.
None
11.
Question: What will the following code print when compiled and run:
public class TestClass {
public static void main(String[] args){
var k = 2;
while(--k){
System.out.println(k);
}
}
}
Select 1 option(s)
1
1
0
2
1
2
1
0
It will keep printing numbers in an infinite loop.
It will not compile.
None
12.
Question: Identify correct statements about java.io.Console class?
Select 1 option(s)
You can read character data from a console but not write to it.
You can read both binary and character data from Console object but you cannot write to it.
You can read both binary and character data from Console object but you can only write character data to it.
You can read as well as write only character data from/to it.
None
13.
Question: Identify correct statements about Java exceptions.
Select 1 option(s)
Errors and its subclasses are meant for situations from which an application can recover while RuntimeException and its subclasses are meant for situations from which an application cannot recover.
RuntimeException and its subclasses are used for recoverable situations.
Neither Errors nor RuntimeExceptions are used for recoverable situations. RuntimeExceptions should be identified during testing and eliminated by fixing the code, while Errors should be eliminated by fixing the environment.
Both - Errors and RuntimeExceptions - are recoverable and should be caught. A helpful message should be shown to the user instead of generating a stack trace on the console.
None
14.
Question: You are writing a piece of code that determines tax rate on a given grossIncome. The tax rate is to be computed as follows -
If grossIncome is less than or equals to 18000, taxRate is 0.
If grossIncome is more than 18000 but less than or equal to 36000, taxRate is 10%
If grossIncome is more than 36000, taxRate is 20%.
Which of following code fragments do it correctly?
Select 3 option(s)
double taxRate = grossIncome<=18000 ? 0 : (grossIncome<=36000) ? .1 : .2;
double taxRate = .2;
taxRate = grossIncome<=18000?0:.1;
taxRate = grossIncome<=36000?.1:.2;
double taxRate = 0;
if(grossIncome>36000) taxRate = .20;
if(grossIncome>18000 && grossIncome<=36000) taxRate = .10;
double taxRate = .2;
if(grossIncome>36000) {
taxRate = .2;
}else taxRate = 0;
if(grossIncome>18000 ) {
taxRate = .1;
}
double taxRate = 0;
taxRate = grossIncome>18000?grossIncome<=36000?.1:.2:0;
15.
Question: What will the following code print when compiled and run?
record Student(int id, String... subjects) {
public Student{
if(id<0) throw new IllegalArgumentException();
if( subjects == null || subjects.length == 0) {
subjects = new String[] {"english" };
}
}
}
public class TestClass{
public static void main(String[] args) {
Student s = new Student(123, null);
System.out.println(s);
}
}
Select 1 option(s)
It will not compile.
It will throw a NullPointerException at run time.
Student[id=123, subjects=null]
Student[id=123, subjects=[Ljava.lang.String;@568db2f2]
None
16.
Question: What will the following code print?
Duration d = Duration.ofDays(1);
System.out.println(d);
d = Duration.ofMinutes(0);
System.out.println(d);
Period p = Period.ofMonths(0);
System.out.println(p);
Select 1 option(s)
PT1D
PT0M
P0M
PT24H
PT0S
P0D
PT0S
PT0M
P0M
0
PT0S
P0D
None
17.
Question: What will the following code print when compiled and run?
var tickers = List.of("A", "D", "E", "C", "A");
var ratio = List.of(1.0, 1.2, 1.5, 1.8, 2.0);
var map1 = IntStream.range(0, tickers.size())
.boxed()
.collect(Collectors.toMap(
i -> tickers.get(i),
i -> 1.0/ratio.get(i), (x, y) -> x+y)) ; //<<----- LINE 1
var map2 = map1.entrySet().stream().sorted(Map.Entry.comparingByKey())
.collect(
Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue,
(x, y) -> x-y,
LinkedHashMap::new)
); //<<----- LINE 2
map2.forEach((var k, var v)->System.out.printf("%s = %.2f\n",k, v));
Select 1 option(s)
A = 1.50
C = 0.56
D = 0.83
E = 0.67
E = 0.67
D = 0.83
C = 0.56
A = 1.50
exception at line 1.
exception at line 2.
A = 1.50
D = 0.83
E = 0.67
C = 0.56
A = 1.50
None
18.
Question: What will the following program print when run?
public class ChangeTest {
private int myValue = 0;
public void showOne(int myValue){
myValue = myValue;
System.out.println(this.myValue);
}
public void showTwo(int myValue){
this.myValue = myValue;
System.out.println(this.myValue);
}
public static void main(String[] args) {
var ct = new ChangeTest();
ct.showOne(100);
ct.showTwo(200);
}
}
Select 1 option(s)
0 followed by 100.
100 followed by 100.
0 followed by 200.
100 followed by 200.
None
19.
Question: What will the following code snippet print?
List s1 = new ArrayList( );
try{
while(true){
s1.add("sdfa");
}
}catch(RuntimeException e){
e.printStackTrace();
}
System.out.println(s1.size());
Select 1 option(s)
It will not compile.
It will print a RuntimeException stack trace from the catch clause.
It will throw an error at runtime that will not be caught by the catch block.
It will print a stack trace from the catch clause and a number depending on the memory available in the system.
It will only print a number depending on the memory available in the system.
None
20.
Question: Which is the earliest line in the following code after which the object created on line // 1 can be garbage collected, assuming no compiler optimizations are done?
public class NewClass{
private Object o;
void doSomething(Object s){ o = s; }
public static void main(String args[]){
Object obj = new Object(); // 1
NewClass tc = new NewClass(); //2
tc.doSomething(obj); //3
obj = new Object(); //4
obj = null; //5
tc.doSomething(obj); //6
}
}
Select 1 option(s)
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
None
21.
Question: Which statements about the following code are correct?
interface House{
public default String getAddress(){
return "101 Main Str";
}
}
interface Office {
public default String getAddress(){
return "101 Smart Str";
}
}
class HomeOffice implements House, Office{
public String getAddress(){
return "R No 1, Home";
}
}
public class TestClass {
public static void main(String[] args) {
House h = new HomeOffice(); //1
System.out.println(h.getAddress()); //2
}
}
Select 1 option(s)
Code for class HomeOffice will cause compilation to fail.
Line at //1 will cause compilation to fail.
Line at //2 will cause compilation to fail.
The code will compile successfully if the getAddress method is removed from class HomeOffice.
It will compile fine and print R No 1, Home when run.
None
22.
Question: Checked exceptions are meant for...
Select 1 option(s)
exceptional conditions external to an application that a well written application should anticipate and from which it can recover.
exceptional conditions external to the program that a well written program cannot anticipate but should recover from.
exceptional conditions from which recovery is difficult or impossible.
exceptional situations internal to an application that the application can anticipate but cannot recover from.
None
23.
Question: Identify correct statements about the following code:
import java.util.*;
class Student{
int marks;
}
class TestClass {
var k = new Student(); //1
public static void main(String[] args) {
var s = new Student(){ //2
@Override
public String toString(){ return "student obj"; };
};
var slist = Set.of(new Student()); //3
for(var i : slist){ //4
System.out.println(i);
}
slist.removeIf((var s1) -> s1.marks<0); //5
}
}
Select 1 option(s)
It will compile without any error.
Compilation error at //1
Compilation error at //2
Compilation error at //3
Compilation error at //4
Compilation error at //5
None
24.
Question: Given:
class T extends Thread
{
public static Lock lock = new ReentrantLock();
public T(String name){ super(name); }
static StringBuilder data = new StringBuilder();
public void run()
{
if(lock.tryLock()){
try{
lock.lock();
data.append("hello");
}finally{
lock.unlock();
}
}
}
}
public class TestClass
{
public static void main(String args[]) throws Exception
{
T t1 = new T("T1");
t1.start();
try{
t1.lock.lock();
System.out.println(t1.data);
}finally{
t1.lock.unlock();
}
}
}
Identify correct statement(s) about the above code.
Select 2 option(s)
It may print hello and end.
It may print hello but the program will not end (i.e. it will hang).
It will never print hello.
The program will either hang or it will terminate after printing an empty string.
It may print an empty string and then hang.
25.
Question: Given:
module abc.print{
requires org.pdf;
provides org.pdf.Print with com.abc.print.PrintImpl;
}
Identify correct statements about the above module.
Select 1 option(s)
org.pdf.Print must be an interface.
org.pdf.Print must be an interface or an abstract class.
com.abc.print.PrintImpl must have a no-args constructor.
com.abc.print.PrintImpl must implement (or extend) org.pdf.Print.
None of the above are correct.
None
26.
Question: Given:
public static float parseFloat1(String s1){
try{
return Float.parseFloat(s1);
}catch(NumberFormatException e){
return 0.0f;
}catch(IllegalArgumentException e){
return Float.NaN;
}
}
Identify correct statements.
Select 1 option(s)
Calling parseFloat1(""+Float.NEGATIVE_INFINITY); will return 0.0f.
Calling parseFloat1(""+Float.POSITIVE_INFINITY); will return 0.0f.
Calling parseFloat1("junk"); will return 0.0f.
Calling parseFloat1("-Infinity"); will return NaN.
Calling parseFloat1("NaN"); will return 0.0f.
None
27.
Question: Given:
enum Card
{
HEART, CLUB, SPADE, DIAMOND;
}
Which of the following code fragments will print
HEART CLUB SPADE DIAMOND
in that order?
Select 1 option(s)
for(var i=0; i<4; i++) System.out.println(Card[i]+" ");
while(Card.hasNext()) System.out.println(Card.next()+" ");
for(var c : Card.values()) System.out.print(c+" ");
for(var i=0; i<4; i++) System.out.println(Card.ordinal(i)+" ");
None of these.
None
28.
Question: What will be the result of attempting to compile and run the following program?
public class TestClass{
public static void main(String args[]){
try{
RuntimeException re = null;
throw re;
}
catch(Exception e){
System.out.println(e);
}
}
}
Select 1 option(s)
The code will fail to compile, since RuntimeException cannot be caught by catching an Exception.
The program will fail to compile, since re is null.
The program will compile without error and will print java.lang.RuntimeException when run.
The program will compile without error and will print java.lang.NullPointerException when run.
The program will compile without error and will run and print null.
None
29.
Question: What will the following code print?
var ca = new char[]{'a', 'b', 'c', 'd', 'e'};
var i = 0;
for(var c : ca){
switch(c){
case 'a' -> i++;
case 'b' -> ++i;
case 'c', 'd' -> i++;
}
}
System.out.println("i = "+i);
Select 1 option(s)
i = 3
i = 4
i = 5
i = 6
Compilation failure because default statement is necessary in this situation.
None
30.
Question: Given:
String qr = INSERT CODE HERE
try(PreparedStatement ps = connection.prepareStatement(qr);){
...
}
What can be inserted in the above code?
Select 1 option(s)
None
31.
Question: What will the following code print when compiled and run?
class StringWrapper {
private String theVal;
public StringWrapper(String str){ this.theVal = str; }
}
public class Tester{
public static void main(String[] args) {
StringWrapper sw = new StringWrapper("How are you?");
StringBuilder sb = new StringBuilder("How are you?");
System.out.println("Hello, "+sw);
System.out.println("Hello, "+sb);
}
}
Select 1 option(s)
None
32.
Question: Which of the following statements are acceptable?
Select 4 option(s)
Object o = new java.io.File("a.txt");
(Assume that java.io.File is a valid class with a constructor that takes a String.)
Boolean bool = false;
char ch = 10;
Thread t = new Runnable();
(Assume that Runnable is a valid interface.)
Runnable r = new Thread();
(Assume that Thread is a class that implements Runnable interface)
33.
Question: Given:
Which of the following code fragments when inserted in the above code independent of each other will cause it to print java?
Select 1 option(s)
None
34.
Question: What will be a part of the output when the following code is compiled and run?
class Boo {
int boo = 10;
public Boo(int k){ System.out.println("In Boo k = "+k); boo = k;}
}
class BooBoo extends Boo {
public BooBoo(int k ){ super(k); System.out.println("In BooBoo k = "+k); }
}
class Moo extends BooBoo implements Serializable {
int moo = 10;
public Moo(){ super(5); System.out.println("In Moo"); }
}
public class TestClass {
public static void main(String[] args) throws Exception{
var moo = new Moo();
var fos = new FileOutputStream("c:\\temp\\moo1.ser");
var os = new ObjectOutputStream(fos);
os.writeObject(moo);
os.close();
var fis = new FileInputStream("c:\\temp\\moo1.ser");
var is = new ObjectInputStream(fis);
moo = (Moo) is.readObject();
is.close();
}
}
Select 3 option(s)
In Boo k = 5
In BooBoo k = 5
In Boo k = 0
In BooBoo k = 0
In Moo
It will throw an exception at runtime.
It will not compile.
35.
Question: What will the following code print when compiled and run?
List messages =
Arrays.asList(new StringBuilder(), new StringBuilder());
messages.stream().forEach(s->s.append("helloworld"));
messages.forEach(s->{
s.insert(5,",");
System.out.println(s);
});
Select 1 option(s)
It will not print anything.
It will not compile.
It will throw IllegalStateException at runtime.
hello,world
hello,world
helloworld
helloworld
None
36.
Question: Consider :
class A { public void perform_work(){} }
class B extends A { public void perform_work(){} }
class C extends B { public void perform_work(){} }
How can you let perform_work() method of A to be called from an instance method in C?
Select 1 option(s)
( (A) this ).perform_work( );
super.perform_work( );
super.super.perform_work( );
this.super.perform_work( );
It is not possible.
None
37.
Question: What will the following code print when compiled and run?
Â
Select 1 option(s)
Hello : BillGeorgeObama
Hello : BillHello : GeorgeHello : Obama
BillGeorgeObamaHello :
BillGeorgeObama
It will throw an exception at run time.
None
38.
Question: Complete the following code:
enum Card {
CLUB, DIAMOND, HEART, SPADE
}
public class TestClass{
public static String getColor(Card c){
INSERT CODE HERE
}
public static void main(String[] args) {
System.out.println(getColor(Card.CLUB));
}
}
Select 2 option(s)
return switch(c){
case CLUB, SPADE -> "BLACK"; break;
case DIAMOND, HEART -> "RED";
};
return switch(c){
case CLUB, SPADE -> "BLACK";
case DIAMOND, HEART -> "RED";
default -> "YELLOW";
};
switch(c){
case CLUB, SPADE -> return "BLACK";
case DIAMOND, HEART -> return "RED";
};
return switch(c){
case CLUB, SPADE -> "BLACK";
};
return switch(c){
case CLUB, SPADE -> { yield "BLACK"; }
case DIAMOND, HEART -> { yield "RED"; }
};
39.
Question: What will be the output of the following program?
class TestClass{
public static void main(String[] args) throws Exception{
try{
amethod();
System.out.println("try ");
}
catch(Exception e){
System.out.print("catch ");
}
finally {
System.out.print("finally ");
}
System.out.print("out ");
}
public static void amethod(){ }
}
Select 1 option(s)
try finally
try finally out
try out
catch finally out
It will not compile because amethod() does not throw any exception.
None
40.
Question: What will the following code print?
DateTimeFormatter df = DateTimeFormatter.ofPattern("eeee");
LocalDate d = LocalDate.of(2000, 1, 1); //assume that it was Saturday on this date
System.out.println(df.format(d));
Select 1 option(s)
Satu
Saturday
Sat
0007
7
None
41.
Question: What will the following code print when compiled and run?
public class Device implements AutoCloseable{
boolean open = false;
int index;
public Device(int index){
this.index = index;
open = true;
}
public void write() throws IOException{
throw new RuntimeException("Can't write!");
}
public void close(){
open = false;
System.out.println("Device closed "+index);
}
public static void main(String[] args) {
Device d1 = new Device(1);
try(d1;
Device d2 = new Device(2);
Device d3 = new Device(3)){
d2.write();
d1.close();
}catch(Exception e){
System.out.println("Got Exception "+e.getMessage());
}
}
}
Select 1 option(s)
Device closed 3
Device closed 2
Got Exception Can't write!
Device closed 2
Device closed 3
Got Exception Can't write!
Device closed 1
Device closed 2
Device closed 3
Got Exception Can't write!
Device closed 1
Device closed 3
Device closed 2
Got Exception Can't write!
Device closed 3
Device closed 2
Device closed 1
Got Exception Can't write!
None
42.
Question: What will be the result of compiling and running the following code?
class Base{
public Object getValue(){ return new Object(); } //1
}
class Base2 extends Base{
public String getValue(){ return "hello"; } //2
}
public class TestClass{
public static void main(String[] args){
Base b = new Base2();
System.out.println(b.getValue()); //3
}
}
Select 1 option(s)
It will print the hash code of the object.
It will print hello.
Compile time error at //1.
Compile time error at //2.
Compile time error at //3.
None
43.
Question: Consider the following code:
public class TestOuter
{
public void myOuterMethod()
{
// 1
}
public class TestInner { }
public static void main(String[] args)
{
var to = new TestOuter();
// 2
}
}
Which of the following options correctly instantiates a TestInner object?
Select 2 option(s)
new TestInner(); at //1
new TestInner(); at //2
new to.TestInner(); at //2
new TestOuter.TestInner(); at //2
new TestOuter().new TestInner(); at //1
44.
Question: Which digits and in what order will be printed when the following program is run?
public class TestClass{
public static void main(String args[]){
int k = 0;
try{
int i = 5/k;
}
catch (ArithmeticException e){
System.out.println("1");
}
catch (RuntimeException e){
System.out.println("2");
return ;
}
catch (Exception e){
System.out.println("3");
}
finally{
System.out.println("4");
}
System.out.println("5");
}
}
Select 1 option(s)
The program will print 5.
The program will print 1 and 4, in that order.
The program will print 1, 2 and 4, in that order.
The program will print 1, 4 and 5, in that order.
The program will print 1,2, 4 and 5, in that order.
None
45.
Question: Which of the following statements about deadlock is correct?
Select 1 option(s)
A deadlock occurs when threads become so busy in responding to each other that they are unable to perform any real work.
Deadlock occurs when a thread is frequently unable to get access to a resource because the resource is hogged by other threads most of the time.
Thread 1 and 2 are said to be deadlocked when Thread 1 is blocked waiting for Thread 2 to release a resource, while Thread 2 is blocked waiting for Thread 1 to release another resource.
A deadlock is caused by starvation, which in turn is caused by a live lock.
A deadlock is caused when, in a multi core CPU system, one of the cores get offline or corrupt.
None
46.
Question: What will the following code print when run?
class MyCallable implements Callable{
public String call() throws Exception {
Thread.sleep(50000);
return "DONE";
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
var es = Executors.newSingleThreadExecutor();
var future = es.submit(new MyCallable());
System.out.println(future.get()); //1
es.shutdownNow(); //2
}
}
Select 1 option(s)
DONE
null
It will throw an exception at run time at line marked //1
It will throw an exception at run time at line marked //2
None
47.
Question: Which of the following declarations is/are valid inside a static method:
1. bool b = null;
2. boolean b = 1;
3. boolean b = true|false;
4. bool b = (10<11);
5. boolean b = true||false;
6. var b = 10>11;
Select 1 option(s)
1 and 4
2, 3, 5, and 6
2 and 3
3, 5, and 6
5 and 6
3 and 5
1, 4, and 6
None
48.
Question: Given:
public class TestClass
{
public static void main(String args[])
{
B b = new C();
A a = b;
INSERT CODE HERE
}
}
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 can be inserted in the above code?
Select 2 option(s)
if (a instanceof A a1) a1.a();
if (a instanceof B b1) b1.a();
if (a instanceof B b2) b2.c();
if (a instanceof C c1) c1.c();
49.
Question: Consider the following code:
Statement stmt = null;
try(Connection c = DriverManager.getConnection("jdbc:derby://localhost:1527/sample",
"app", "app"))
{
stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("select * from STUDENT");
while(rs.next()){
System.out.println(rs.getString(1));
}
}
catch(SQLException e){
System.out.println("Exception "+e);
}
Which objects can be successfully used to query the database after the try block ends without any exception?
Select 1 option(s)
stmt
c
rs
stmt as well c
None of them.
None
50.
Question: What will the following class print when executed?
class Test{
static boolean a;
static boolean b;
static boolean c;
public static void main (String[] args){
boolean bool = (a = true) || (b = true) && (c = true);
System.out.print(a + ", " + b + ", " + c);
}
}
Select 1 option(s)
true, false, true
true, true, false
true, false, false
true, true, true
None
51.
Question: Given:
abstract class Base{
abstract int power();
}
class A extends Base{
@Override
int power(){ return 0; }
}
class AA extends A{
@Override
int power(){ return 1; }
void mAA(){
System.out.println("mAA");
}
}
class B extends Base{
@Override
int power(){ return 1; }
}
public class TestClass
{
void processBase(Base base){
INSERT CODE HERE
}
}
What can be inserted in the above code?
Select 2 option(s)
if(base instanceof A a && a instanceof AA aa ){
aa.mAA();
}
if(base instanceof A a && a.power() == 1 ){
a.mAA();
}
if(base instanceof A a && a.power() == 1 ){
((AA)a).mAA();
}
if(base instanceof B b || base instanceof A a ){
if(b!=null) System.out.println(b.power());
if(a!=null) System.out.println(a.power());
}
52.
Question: Consider the program shown in exhibit and select the right option(s).
public class TestClass
{
static StringBuffer sb1 = new StringBuffer();
static StringBuffer sb2 = new StringBuffer();
public static void main(String[] args)
{
new Thread
(
new Runnable()
{
public void run()
{
synchronized(sb1)
{
sb1.append("X");
synchronized(sb2)
{
sb2.append("Y");
}
}
System.out.println(sb1);
}
}
).start();
new Thread
(
new Runnable()
{
public void run()
{
synchronized(sb2)
{
sb2.append("Y");
synchronized(sb1)
{
sb1.append("X");
}
}
System.out.println(sb2);
}
}
).start();
}
}
Select 1 option(s)
It will print XX followed by YY
It will print YY followed by XX
It will print XY followed by YX
The above code may result in a deadlock and so nothing can be said for sure about the output.
None
53.
Question: Given:
class NewException extends Exception {}
class AnotherException extends Exception {}
public class ExceptionTest{
public static void main(String[] args) {
try{
if(args.length == 0) m2(); else m3();
}
*INSERT CODE HERE*
}
public static void m2() throws NewException { throw new NewException(); }
public static void m3() throws AnotherException{ throw new AnotherException(); }
}
Which of the following options can be inserted in the above code to make it compile?
Select 3 option(s)
catch(NewException|Exception ne){ }
catch(Exception|AnotherException ne){ }
catch(NewException|AnotherException ne){ }
catch(NewException ne){ }
catch(AnotherException ne){ }
catch(AnotherException ne){ }
catch(NewException ne){ }
54.
Question: Which of the statements regarding the following code are correct?
public class TestClass{
static int a;
int b;
public TestClass(){
int c;
c = a;
a++;
b += c;
}
public static void main(String args[]) { new TestClass(); }
}
Select 1 option(s)
The code will fail to compile because the constructor is trying to access static members.
The code will fail to compile because the constructor is trying to use static member variable a before it has been initialized.
The code will fail to compile because the constructor is trying to use member variable b before it has been initialized.
The code will fail to compile because the constructor is trying to use local variable c before it has been initialized.
The code will compile and run without any problem.
None
55.
Question: What will the following code print?
List ls = Arrays.asList("Tom Cruise", "Tom Hart",
"Tom Hanks", "Tom Brady");
Predicate p = str->{
System.out.println("Looking...");
return str.indexOf("Tom") > -1;
};
boolean flag = ls.stream().filter(str->str.length()>8).allMatch(p);
Select 1 option(s)
It will not print anything.
It will not print anything but will throw an exception at run time.
Looking...
Looking...
Looking...
< exception stack trace >
Looking...
Looking...
Looking...
Looking...
Looking...
Looking...
Looking...
Looking...
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