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
Blog
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
Blog
Welcome to your Standard Java Test - 10
Name
Email
Phone
1.
Question: Consider the following class written by a novice programmer.
class Elliptical{
public int radiusA, radiusB;
public int sum = 100;
public void setRadius(int r){
if(r>99) throw new IllegalArgumentException();
radiusA = r;
radiusB = sum - radiusA;
}
}
After some time, the requirements changed and the programmer now wants to make sure that radiusB is always (200 - radiusA) instead of (100 - radiusA) without breaking existing code that other people have written. Which of the following will accomplish his goal?
Select 1 option(s)
Make sum = 200;
Make sum = 200 and make it private.
Make sum = 200 and make all fields (radiusA, radiusB, and sum) private.
Write another method setRadius2(int r) and set radiusB accordingly in this method.
His goal cannot be accomplished.
This class will not compile.
None
2.
Question: Consider the following classes:
class A implements Runnable{ ...}
class B extends A implements Observer { ...}
(Assume that Observer has no relation to Runnable.)
and the declarations :
A a = new A() ;
B b = new B();
Which of the following Java code fragments will compile and execute without throwing exceptions?
Select 2 option(s)
Object o = a; Runnable r = o;
Object o = a; Runnable r = (Runnable) o;
Object o = a; Observer ob = (Observer) o ;
Object o = b; Observer o2 = o;
Object o = b; Runnable r = (Runnable) b;
3.
Question: What will the following code print when compiled and run?
import java.io.Serializable;
class Booby{
int i; public Booby(){ i = 10; System.out.print("Booby"); }
}
class Dooby extends Booby implements Serializable {
int j; public Dooby(){ j = 20; System.out.print("Dooby"); }
}
class Tooby extends Dooby{
int k; public Tooby(){ k = 30; System.out.print("Tooby"); }
}
public class TestClass {
public static void main(String[] args) throws Exception{
var t = new Tooby();
t.i = 100;
var oos = new ObjectOutputStream(new FileOutputStream("c:\\temp\\test.ser"));
oos.writeObject(t); oos.close();
var ois = new ObjectInputStream(new FileInputStream("c:\\temp\\test.ser"));
t = (Tooby) ois.readObject();ois.close();
System.out.println(t.i+" "+t.j+" "+t.k);
}
}
Select 1 option(s)
Booby Dooby Tooby 100 20 30
Booby Dooby Tooby Booby Dooby Tooby 10 20 30
Booby Dooby Tooby Booby 10 20 30
Booby Dooby Tooby Booby 0 20 30
Booby Dooby Tooby Booby 100 20 30
Booby Dooby Tooby Booby Dooby Tooby 100 20 30
None
4.
Question: What will be the output of the following class.
class Test{
public static void main(String[] args){
int j = 1;
try{
int i = doIt() / (j = 2);
} catch (Exception e){
System.out.println(" j = " + j);
}
}
public static int doIt() throws Exception { throw new Exception("FORGET IT"); }
}
Select 1 option(s)
It will print j = 1;
It will print j = 2;
The value of j cannot be determined.
It will not compile.
None of the above.
None
5.
Question: 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?
Select 5 option(s)
taxId
name
criteria
count
k
sum
6.
Question: Which line in the following code will cause the compilation to fail?
public class TestClass {
public static void main(String[] args) throws Exception {
work(); //LINE 10
int j = j1; //LINE 11
int j1 = (double) x; //LINE 12
}
public static void work() throws Exception{
System.out.println(x); //LINE 15
}
static double x; //19
}
Select 2 option(s)
Line 10
Line 11
Line 12
Line 15
Line 19
7.
Question: Which of these assignments are valid?
Select 3 option(s)
short s = 12 ;
long g = 012 ;
int i = (int) false;
float f = -123;
float d = 0 * 1.5;
8.
Question: Consider the following lines of code:
boolean greenLight = true;
boolean pedestrian = false;
boolean rightTurn = true;
boolean otherLane = false;
You can go ahead only if the following expression evaluates to 'true' :
(( (rightTurn && !pedestrian || otherLane) || ( ? && !pedestrian && greenLight ) ) == true )
What variables can you put in place of '?' so that you can go ahead?
Select 1 option(s)
RightTurn
OtherLane
Any variable would do.
None of the variable would allow to go.
None
9.
Question: Consider the following class...
public class ParamTest {
public static void printSum(double a, double b){
System.out.println("In double "+(a+b));
}
public static void printSum(float a, float b){
System.out.println("In float "+(a+b));
}
public static void main(String[] args) {
printSum(1.0, 2.0);
}
}
What will be printed?
Select 1 option(s)
In float 3
In float 3.0
In double 3.0
In double 3
It will not compile.
None
10.
Question: Consider the following code:
Connection connection = dataSource.getConnection();
PreparedStatement stmt = connection.prepareStatement("select * from CUSTOMER where EMAILID=?");
stmt.setObject(1, "bob@gmail.com"); //LINE 10
ResultSet rs = stmt.executeQuery();
while(rs.next()){
System.out.println(rs.getString("EMAILID")); //LINE 12
}
connection.close();
Assuming that the query returns exactly 1 row, what will be printed when this code is run?
(Assume that items not specified such as import statements, DB url, and try/catch block are all valid).
Select 1 option(s)
It will throw an exception at //LINE 12.
Compilation will fail due to //Line 12.
It will print bob@gmail.com
It will print bob@gmail.com and then throw an exception.
None
11.
Question: Consider:
public class Outer
{
int i = 10;
class Inner
{
public void methodA()
{
//line 1.
}
}
}
Which of the following statements are valid at line 1 (Select the best answer).
Select 2 option(s)
System.out.println(this.i);
System.out.println(i);
System.out.println(Outer.this.i);
'I' cannot be accessed inside the inner class method.
The code cannot be compiled.
12.
Question: Which of the following four constructs are valid?
1.
switch(5)
{
default :
}
2.
switch(5)
{
default : break;
}
3.
switch(8);
4.
var x = 0;
switch(x){
}
Select 1 option(s)
1, 3
1, 2, 3
3, 4
1, 2, 4
All are valid.
None
13.
Question: Given:
public class Square {
private double side = 0; // LINE 2
public static void main(String[] args) { // LINE 4
Square sq = new Square(); // LINE 5
side = 10; // LINE 6
}
}
What can be done to make this code compile and run?
Select 1 option(s)
replace // LINE 2 with:
private int side = 0;
replace // LINE 2 with:
public int side = 0;
replace // LINE 5 with:
double sq = new Square();
replace // LINE 6 with:
sq.side = 10;
None
14.
Question: What will the following program snippet print?
int i=0, j=11;
do{
if(i > j) { break; }
j--;
}while( ++i < 5);
System.out.println(i+" "+j);
Select 1 option(s)
5 5
5 6
6 6
6 5
4 5
None
15.
Question: Which of the following statements would you need to have in the module-info of a Java Swing based desktop application?
Select 1 option(s)
requires java.swing;
requires javax.swing;
requires java.desktop;
requires javax.desktop;
No special requires clause is necessary because Swing classes are part of the standard JDK.
None
16.
Question: What will the following code fragment print?
Path p1 = Paths.get("\\personal\\readme.txt");
Path p2 = Paths.get("\\index.html");
Path p3 = p1.relativize(p2);
System.out.println(p3);
Select 1 option(s)
\index.html
\personal\index.html
personal\index.html
..\..\index.html
None
17.
Question: Given:
class Triangle{
public int base;
public int height;
private static double ANGLE;
public static double getAngle();
public static void Main(String[] args) {
System.out.println(getAngle());
}
}
Identify the correct statements:
Select 1 option(s)
It will not compile because it does not implement setAngle method.
It will not compile because ANGLE cannot be private.
It will not compile because getAngle() has no body.
It will not compile because ANGLE field is not initialized.
It will not compile because of the name of the method Main instead of main.
None
18.
Question: What will the following code print?
int[] a = { 'h', 'e', 'l'};
int[] b = { 'h', 'e', 'l', 'l', 'o'};
int x = Arrays.compare(a, b);
int y = Arrays.mismatch(a, b);
System.out.println(x+" "+y);
Select 1 option(s)
1 3
-1 3
-2 3
-2 -3
The code will not compile.
None
19.
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)
20.
Question: The following are complete contents of TestClass.java:
class Book{
protected final int pages = 100;
final void mA(){
System.out.println("In B.mA "+pages);
}
}
class Encyclopedia extends Book{
private int pages = 200; //1
void mB(){
System.out.println("In E.mB "+pages);
}
void mA(){ //2
System.out.println("In E.mA "+pages);
}
}
public class TestClass {
public static void main(String[] args) {
Book o1 = new Encyclopedia (); //3
Book o2 = new Book();
o1.mA(); //4
o1.mB(); //5
o2.mA();
}
}
Which lines will cause compilation to fail?
Select 1 option(s)
//1 and //2
//2 and //5
//1 //2 and //5
//1 and //5
//1 and //3
//1 //3 and //4
None
21.
Question: Given:
BiFunction bf = (String s, Integer i) -> { return s.substring(0, i); };
What of the following lambda expressions is equivalent to the one used above?
Select 1 option(s)
(s, i)->s.substring(0, i)
(s, i)->s::substring(0, i)
(s, i)->s:substring(0, i)
s::substring(0, i)
None
22.
Question: Which of these statements are true?
Select 2 option(s)
If a RuntimeException is not caught, the method will terminate and normal execution of the thread will resume.
An overriding method must declare that it throws the same exception classes as the method it overrides.
The main method of a program can declare that it throws checked exceptions.
A method declaring that it throws a certain exception class may throw instances of any subclass of that exception class.
Finally blocks are executed if and only if an exception gets thrown while inside the corresponding try block.
23.
Question: 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 ?
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
24.
Question: Consider the following code:
//Assume appropriate imports
class Person{
String name;
String dob;
public Person(String name, String dob){
this.name = name; this.dob = dob;
}
}
public class SortTest {
public static void main(String[] args) {
ArrayList al = new ArrayList();
al.add(new Person("Paul", "01012000"));
al.add(new Person("Peter", "01011990"));
al.add(new Person("Patrick", "01012002"));
//INSERT CODE HERE
for(Person a : al) System.out.println(a.name+" "+ a.dob);
}
}
What can be inserted in the code so that it will sort the collection of Persons by Person's dob attribute?
Select 1 option(s)
Collections.sort(al, new Comparable
Person
(){
public int compare(Person o1, Person o2) {
return o1.dob.compareTo(o2.dob);
}
});
Collections.sort(al, new Comparator
Person
(){
public int compare(Person o1, Person o2) {
return o1.dob.compareTo(o2.dob);
}
});
Collections.sort(al, new Comparable
Person
(){
public int compare(Person o1, Person o2) {
return o1.dob.compare(o2.dob);
}
});
Collections.sort(al, new Comparator
Person
(){
public int compare(Person o1, Person o2) {
return o1.dob.compare(o2.dob);
}
});
None
25.
Question: Consider the following class...
class TestClass{
void probe(Integer x) { System.out.println("In Integer"); } //2
void probe(Object x) { System.out.println("In Object"); } //3
void probe(Long x) { System.out.println("In Long"); } //4
public static void main(String[] args){
String a = "hello";
new TestClass().probe(a);
}
}
What will be printed?
Select 1 option(s)
In Integer
In Object
In Long
It will not compile.
None
26.
Question: Given the following pairs of method declarations, which of the statements are true?
1.
void perform_work(int time){ }
int perform_work(int time, int speed){ return time*speed ;}
2.
void perform_work(int time){ }
int perform_work(int speed){return speed ;}
3.
void perform_work(int time){ }
void Perform_work(int time){ }
Select 2 option(s)
The first pair of methods will compile correctly and overload the method 'perform_work'.
The second pair of methods will compile correctly and overload the method 'perform_work'.
The third pair of methods will compile correctly and overload the method 'perform_work'.
The second pair of methods will not compile correctly.
The third pair of methods will not compile correctly.
27.
Question: What will the following code print when compiled and run?
import java.util.*;
public class TestClass {
public static void main(String[] args) throws Exception {
ArrayList al = new ArrayList();
al.add("111");
al.add("222");
System.out.println(al.get(al.size()));
}
}
Select 1 option(s)
It will not compile.
It will throw a NullPointerException at run time.
It will throw an IndexOutOfBoundsException at run time.
222
Null
None
28.
Question: Given the following class:
class Person{
private String name;
private java.time.LocalDate dob;
public Person(String name, java.time.LocalDate dob){
this.name = name;
this.dob = dob;
}
//public getters and setters for name and dob
}
and the following method appearing in some other class:
public List getEligiblePersons(List people){
var pl = new ArrayList();
for(var p : people){
if(p.getDob().isBefore(cutoff)){
pl.add(p);
}
}
return pl;
}
Select 2 option(s)
There is no issue with the given code.
A copy of dob parameter should be made and that copy should be assigned to the dob field.
GetEligiblePersons should create a deep copy of the people list before processing the elements.
Person class should provide a copy constructor.
Person class should be made final.
29.
Question: Given:
class A{
public List getList(){
//valid code
};
}
class B extends A{
@Override
*INSERT CODE HERE*
//valid code
};
}
What can be inserted in the above code?
Select 1 option(s)
public List< ? extends Integer > getList(){
public List< ? super Integer > getList(){
public ArrayList< ? extends Number > getList(){
public ArrayList
? super Number
getList(){
public ArrayList
Number
getList(){
None
30.
Question: Given a class named Test, which of these would be valid definitions for a constructor for the class?
Select 1 option(s)
Test(Test b) { }
Test Test( ) { }
Private final Test( ) { }
Void Test( ) { }
Public static void Test(String args[ ] ) { }
None
31.
Question: Given the following method:
public static void copy(String fileName1, String fileName2) throws Exception{
try (
InputStream is = new FileInputStream(fileName1);
OutputStream os = new FileOutputStream(fileName2); ) {
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = is.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
System.out.println("Read and written bytes " + bytesRead);
}
}
}
What will happen fileName1 contains only 100 bytes and fileName2 contains 200 bytes?
Select 1 option(s)
An exception will be thrown while reading from the file.
An exception will be thrown while writing to the file.
FileName2 will end up with 300 bytes.
FileName2 will end up with 200 bytes.
FileName2 will end up with 100 bytes.
None
32.
Question: Given:
List strList = Arrays.asList("a", "aa", "aaa");
Function f = x->x.length();
Consumer c = x->System.out.print("Len:"+x+" ");
strList.stream().map(f).forEach(c);
What will it print when compiled and run?
Select 1 option(s)
A compilation error will occur.
Len:a Len:aa Len:aaa
Len:1 Len:2 Len:3
It will compile and run fine but will not print anything.
None
33.
Question: Given:
class Automobile{
final String getVin(){ return "1234"; }
}
Identify correct statements.
Select 1 option(s)
The following code will not compile because it is missing a zero args constructor:
public final class Car extends Automobile{
}
The following code will not compile because Automobile is final:
class Car{
Automobile a;
}
The following code will not compile because a final class cannot extend any other class:
public final class Car extends Automobile{
}
The following code will compile fine:
final class Car extends Automobile{
}
None
34.
Question: Given:
ConcurrentMap cache = new ConcurrentHashMap();
Which of the given statements are correct about the following code fragment:
if(!cache.containsKey(key)) cache.put(key, value);
(Assume that key and value refer to appropriate objects.)
Select 1 option(s)
This will ensure that an entry in cache will never be overwritten.
To ensure that an entry in cache must never be overwritten, this statement should be replaced with:
cache.putIfAbsent(key, value);
To ensure that an entry in cache must never be overwritten, this statement should be replaced with:
cache.putAtomic(key, value);
To ensure that an entry in cache must never be overwritten, this statement should be enclosed in a synchronized block that synchronizes on "this".
None
35.
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
36.
Question: What will the following code print when compiled and run?
public class DaysTest{
static String[] days = {"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" };
public static void main(String[] args) {
var index = 0;
for(var day : days){
if(index == 3){
break;
}else {
continue;
}
index++;
if(days[index].length()>3){
days[index] = day.substring(0,3);
}
}
System.out.println(days[index]);
}
}
Select 1 option(s)
mon
thu
fri
It will not compile.
It will throw an exception at run time.
None
37.
Question: Consider the following code to count objects and save the most recent object:
int i = 0 ;
Object prevObject ;
public void saveObject(List e ){
prevObject = e ;
i++ ;
}
Which of the following calls will work without throwing an exception?
Select 3 option(s)
SaveObject( new ArrayList() );
Collection c = new ArrayList(); saveObject( c );
List el = new ArrayList(); saveObject(el);
SaveObject(null);
SaveObject(0); //The argument is the number zero and not the letter o
38.
Question: Given:
class Base{
public Map getMap(T t, Z z)
{
return new HashMap();
}
}
class Derived extends Base{
//public TreeMap getMap(T t, Z z) { return new TreeMap(); }; //1
//public Map getMap(Number t, Number z) { return new TreeMap(); }; //2
//public Map getMap(Number t, Number z) { return new HashMap(); }; //3
}
Identify correct statements about the methods defined in Derived assuming they are uncommented one at a time individually.
Select 1 option(s)
//1 correctly overloads while //2 and //3 correctly override the method in Base.
//1 will not compile while //2 and //3 correctly overload the method in Base.
//1 correctly overloads the method in Base while //2 and //3 will not compile.
//1 correctly overrides while //2 and //3 correctly overloads the method in Base.
//1 and //3 will compile while //2 will not.
//1 and //2 will compile while //3 will not.
None
39.
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 can be inserted at //1 and //2 so that it will print the price of all the books having a title that starts with "A"?
List books = Arrays.asList(
new Book("Atlas Shrugged", 10.0),
new Book("Freedom at Midnight", 5.0),
new Book("Gone with the wind", 5.0)
);
Map bookMap = //1 INSERT CODE HERE
//2 INSERT CODE HERE
bookMap.forEach(func);
Select 1 option(s)
None
40.
Question: Given:
class Person{
private String name;
private java.util.Date dob;
public Person(String name, java.util.Date dob){
this.name = name;
this.dob = (java.util.Date) dob.clone();
if(!validateDob(this.dob)) throw new IllegalArgumentException("dob cannot be in future");
}
protected boolean validateDob(java.util.Date dob){
return !dob.after(new java.util.Date());
}
//getter methods for fields not shown
}
What changes should be made to make this class immutable?
Select 2 option(s)
Remove the call to clone() and assign the dob parameter directly to the dob field.
ValidateDob method should be made private.
Person class should be made final.
Name and dob fields should be made final.
41.
Question: What will the following code print when compiled and run?
public static void main(String[] args) {
Float f1 = 10.0f;
Float f2 = 0.0f;
Float f3 = null;
double f = 0.0;
try{
f = f1/f2;
System.out.println(f);
f3 = f1/f2;
}catch(Exception e){
System.out.println("Exception");
}
System.out.println(f3.isInfinite());
}
Select 1 option(s)
Exception
false
Exception
Exception
< stack trace for a NullPointerException >
Infinity
true
Infinity
Exception
< stack trace for a NullPointerException >
None
42.
Question: Which of the following statements can be inserted at // 1 to make the code compile without errors?
public class InitTest{
static int si = 10;
int i;
final boolean bool;
// 1
}
Select 1 option(s)
instance { bool = true; }
InitTest() { si += 10; }
{ si = 5; i = bool ? 1000 : 2000;}
{ i = 1000; }
{ bool = (si > 5); i = 1000; }
None
43.
Question: Consider the following class...
class TestClass{
int x;
public static void main(String[] args){
// lot of code.
}
}
Select 1 option(s)
By declaring x as static, main can access this.x
By declaring x as public, main can access this.x
By declaring x as protected, main can access this.x
Main cannot access this.x as it is declared now.
By declaring x as private, main can access this.x
None
44.
Question: Given:
Connection con = DriverManager.getConnection(dbURL);
con.setAutoCommit(false);
String updateString =
"update SALES " +
"set T_AMOUNT = 100 where T_NAME = 'BOB'";
Statement stmt = con.createStatement();
stmt.executeUpdate(updateString);
//INSERT CODE HERE
What statement should be added to the above code so that the update is committed to the database?
Select 1 option(s)
stmt.commit();
con.commit();
stmt.commit(true);
con.commit(true);
No code is necessary.
None
45.
Question: Given:
double daaa[][][] = new double[3][][];
var d = 100.0;
double[][] daa = new double[1][1];
Which of the following statements can be added to the above code, independent of each other, without causing compilation or runtime errors?
Select 3 option(s)
daaa[0] = d;
daaa[0] = daa;
daaa[0] = daa[0];
daa[1][1] = d;
daa = daaa[0];
double[] newd = daa[0].clone();
46.
Question: What will the following code print when compiled and run?
public class Discounter {
static double percent; //1
int offset = 10, base= 50; //2
public static double calc(double value) {
var coupon, offset, base; //3
if(percent <10){ //4
coupon = 15;
offset = 20;
base = 10;
}
return coupon*offset*base*value/100; //5
}
public static void main(String[] args) {
System.out.println(calc(100));
}
}
Select 1 option(s)
3000
3000.0
compilation error at //3.
compilation error at //4.
compilation error at //5.
Exception at run time.
None
47.
Question: Given:
Path p1 = Paths.get("c:\\a\\b\\c.java");
What will p1.getName(2).toString() return?
Select 1 option(s)
a
b
c
c.java
None
48.
Question: Given the following class code:
public class Transfer implements Runnable{
Account from, to;
double amount;
public Transfer(Account from, Account to, double amount){
this.from = from; this.to = to; this.amount = amount;
}
public void run(){
synchronized(from){
from.setBalance(from.getBalance()-amount);
synchronized(to){
to.setBalance(to.getBalance()+amount);
}
}
}
}
Relevant code for the Account class referred above is as follows:
public class Account{
private String id; private double balance;
//constructor and accessor methods not shown,
}
What will happen when the following code is executed?
var es = Executors.newCachedThreadPool();
var a1 = new Account("A1", 1000);
var a2 = new Account("A1", 1000);
es.submit(new Transfer(a1, a2, 200));
es.submit(new Transfer(a2, a1, 300));
Select 1 option(s)
Code will run successfully without any problem.
The code may enter a deadlock.
The code may enter a livelock.
The code may enter a starvation situation.
None
49.
Question: 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 Iterator getIterator(){
return cal.iterator();
}
}
Given that one thread calls the addData method on an instance of the above class and another thread calls the getIterator method on the same instance at the same time and starts iterating through its values, which of the following options are correct?
(Assume that no other calls have been made on the MyCache instance.)
Select 1 option(s)
The call to addAll may be blocked while the other thread is iterating through the iterator.
Both the threads will complete their operations successfully without getting any exception.
The thread iterating through the Iterator will get a ConcurrentModificationException.
Elements added by the addAll method will automatically be visible through the iterator in the other thread.
None
50.
Question: Consider the following code:
package jqplus;
import java.util.*;
public class Testclass {
public static void main(String[] args) {
NavigableMap mymap = new TreeMap();
mymap.put("a", "apple"); mymap.put("b", "boy"); mymap.put("c", "cat");
mymap.put("aa", "apple1"); mymap.put("bb", "boy1"); mymap.put("cc", "cat1");
mymap.pollLastEntry(); //LINE 1
mymap.pollFirstEntry(); //LINE 2
NavigableMap tailmap = mymap.tailMap("bb", false); //LINE 3
System.out.println(tailmap.pollFirstEntry()); //LINE 4
System.out.println(mymap.size()); //LINE 5
}
}
What will be returned by the call to tailmap.pollFirstEntry() at //LINE 4 and mymap.size() at //LINE 5?
Select 1 option(s)
A ConcurrentModificationException will be thrown at //LINE 1.
It will return c - cat and 3.
It will return c - cat and 4.
It will return bb - boy1 and 4.
It will return null and 4.
None
51.
Question: Identify the correct statements about the following code fragment:
var fw = new FileWriter("c:\\temp\\test.txt");
var bfw = new BufferedWriter(fw);
bfw.writeUTF("hello"); //1
bfw.newLine(); //2
bfw.write("world"); //3
Select 1 option(s)
Compilation error at //1.
Compilation error at //2.
Compilation error at //3.
It will compile but will throw an exception at runtime.
It will write "hello" in UTF encoding, followed by a new line, and then "world" in default encoding to test.txt.
None
52.
Question: Given:
public class TableTest {
static String[][] table;
public static void main(String[] args) {
String[] x = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
String[] y1 = { "1", "2", "3", "4", "5" };
String[] y2 = { "a", "b", "c" };
table = new String[3][];
table[0] = x;
table[1] = y1;
table[2] = y2;
//INSERT CODE HERE
}
}
What can be inserted in the above code to make it print Sun5c?
Select 1 option(s)
for(String[] row : table){
System.out.print(row[row.length]);
}
int i = 0;
for(String[] col : table){
i++;
if(i==col.length){
System.out.print(table[col.length][i]);
}
}
for(var row : table){
System.out.print(row[row.length-1]);
}
for(int i=0; i<table.length-1; i++){
int j = table[i].length-1;
System.out.print(table[i][j]);
}
None
53.
Question: Given:
public class Person{
private String name;
private java.util.Date dob;
public Person(String name, java.util.Date dob){
this.name = name;
this.dob = dob;
}
public String getName(){ return name; }
public java.util.Date getDob(){ return dob; }
}
What, if anything, is wrong with the above code from secure coding guidlines perspective?
Select 1 option(s)
There is nothing wrong.
Setter methods for name and dob should be added.
Name and dob should be set using setter methods instead of the constructor.
The constructor should clone name and dob parameters before assigning them to the instance fields.
The getDob method should return a clone of dob.
None
54.
Question: Consider the following code:
import java.util.*;
public class TestClass
{
static String[] sa = { "charlie", "bob", "andy", "dave" };
public static void main(String[] args)
{
// 1 insert code here.
}
}
Which of the given options (independent of each other or together) must be inserted at //1 so that it will print 2?
Select 2 option(s)
System.out.println(Arrays.search(sa, "andy"));
System.out.println(Arrays.linearSearch(sa, "andy"));
Arrays.sort(sa);
System.out.println(Arrays.binarySearch(sa, "charlie"));
Only option 2 is enough.
55.
Question: What will be printed when the following code is compiled and run?
package trywithresources;
import java.io.IOException;
public class Device implements AutoCloseable{
String header = null;
public void open(){
header = "OPENED";
System.out.println("Device Opened");
}
public String read() throws IOException{
throw new IOException("Unknown");
}
public void writeHeader(String str) throws IOException{
System.out.println("Writing : "+str);
header = str;
}
public void close(){
header = null;
System.out.println("Device closed");
}
public static void testDevice(){
Device d = new Device();
try(d){
d.open();
d.read();
d.writeHeader("TEST");
d.close();
}catch(IOException e){
System.out.println("Got Exception");
}
}
public static void main(String[] args) {
Device.testDevice();
}
}
Select 1 option(s)
Device Opened
Device closed
Got Exception
Device Opened
Got Exception
Device closed
Device Opened
Got Exception
The code will not compile.
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
Blog
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
Blog
Contact Us
(510) 550 - 7200
39141 Civic Center Dr, Suite 201, Fremont, CA 94539, US