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 - 15
Name
Email
Phone
1.
Question: Which of the following implementations of a max() method will correctly return the largest value?
Select 1 option(s)
None
2.
Question: MOVE What is the result of compiling and running the following code ?
public class TestClass{
static int si = 10;
public static void main (String args[]){
new TestClass();
}
public TestClass(){
System.out.println(this);
}
public String toString(){
return "TestClass.si = "+this.si;
}
}
Select 1 option(s)
The class will not compile because you cannot override toString() method.
The class will not compile as si being static, this.si is not a valid statement.
It will print TestClass@nnnnnnnn, where nnnnnnnn is the hash code of the TestClass object referred to by 'this'.
It will print TestClass.si = 10.
None of the above.
None
3.
Question: Consider the following program...
class Super { }
class Sub extends Super { }
public class TestClass{
public static void main(String[] args){
Super s1 = new Super(); //1
Sub s2 = new Sub(); //2
s1 = (Super) s2; //3
}
}
Which of the following statements are correct?
Select 1 option(s)
It will compile and run without any problems.
It will compile but WILL throw ClassCastException at runtime.
It will compile but MAY throw ClassCastException at runtime.
It will not compile.
None of the above.
None
4.
Question: 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
}
}
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
5.
Question: 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.)
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); };
}
6.
Question: Which of the following options are guideline(s) to protect confidential information?
Select 3 option(s)
Confidential information should not be stored in the application.
Confidential and other information should be treated uniformly.
Access to confidential information should be limited.
Objects containing confidential information should be encapsulated properly.
Handle information transparently to improve diagnostics.
Clearly identify and label confidential information.
7.
Question: Which of the following methods are available in java.io.Console?
Select 5 option(s)
readPassword
reader
writer
readLine
read
getPassword
format
8.
Question: Consider the following program...
class ArrayTest{
public static void main(String[] args){
var ia[][] = { {1, 2}, null };
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
System.out.println(ia[i][j]);
}
}
Which of the following statements are true?
Select 1 option(s)
It will throw an ArrayIndexOutOfBoundsException at Runtime.
It will throw a NullPointerException at Runtime.
It will compile and run without throwing any exceptions.
It will compile and throw a NullPointerException at runtime if var ia[][] = { {1, 2}, null }; is replaced with var ia = new int[][]{ {1, 2}, null };.
It will compile and throw a NullPointerException at runtime if var ia[][] = { {1, 2}, null }; is replaced with var ia[][] = new int[][]{ {1, 2}, null };.
None
9.
Question: Given:
String qr = "insert into USERINFO values( ?, ?, ?)";
try(PreparedStatement ps = c.prepareStatement(qr);)
{
ps.setObject(0, 1); //1
ps.setObject(1, "Ally A", JDBCType.VARCHAR); //2
ps.setObject(2, "101 main str"); //3
ps.executeUpdate(); //4
ps.setObject(1, "Bob B"); //5
ps.setNull(2, java.sql.Types.VARCHAR); //5
ps.executeUpdate(); //6
}
What will be the result?
Select 1 option(s)
Two rows with the following values will be inserted in the USERINFO table:
1, Ally A, 101 main str
null, Bob B, null
Two rows with the following values will be inserted in the USERINFO table:
1, Ally A, 101 main str
1, Bob B, 101 main str
An exception will be thrown at //1.
An exception will be thrown at //2.
An exception will be thrown at //3.
An exception will be thrown at //4.
An exception will be thrown at //5.
An exception will be thrown at //6.
None
10.
Question: What will the following code print when compiled and run?
interface Eatable{
int types = 10;
}
class Food implements Eatable {
public static int types = 20;
}
public class Fruit extends Food implements Eatable{ //LINE1
public static void main(String[] args) {
types = 30; //LINE 2
System.out.println(types); //LINE 3
}
}
Select 1 option(s)
Compilation failure at //LINE 1.
Compilation failure at //LINE 2.
Compilation failure at //LINE 3.
10
20
30
Compilation failure at //LINE 2 as well as at //LINE 3.
None
11.
Question: What will the following code print?
char[] a = { 'h', 'e', 'l', 'l'};
char[] b = { };
int x = Arrays.compare(a, b);
int y = Arrays.mismatch(a, b);
System.out.println(x+" "+y);
Select 1 option(s)
It will throw an IndexOutOfBoundsException at run time.
4 0
1 0
-4 -4
-4 4
None
12.
Question: What can be inserted at line 2 in the code snippet given below?
String[] names = {"Alex", "Bob", "Charlie" };
//Insert code here
System.out.println(list.get(0));
Select 2 option(s)
13.
Question: How can you initialize a StringBuilder to have a capacity of at least 100 characters?
Select 2 option(s)
StringBuilder sb = new StringBuilder(100);
StringBuilder sb = StringBuilder.getInstance(100);
StringBuilder sb = new StringBuilder();
sb.setCapacity(100);
StringBuilder sb = new StringBuilder();
sb.ensureCapacity(100);
14.
Question: 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 );
}
}
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
15.
Question: What will the following code print when compiled and run?
var numA = new Integer[]{1, 2};
var list1 = List.of(numA);
numA[0] = 2;
var list2 = List.copyOf(list1);
System.out.println(list1+" "+list2);
Select 1 option(s)
It will not compile.
[1, 2] [1, 2]
[2, 2] [1, 2]
[2, 2] [2, 2]
None
16.
Question: Given the following set of member declarations, which of the following is true?
int a; // (1)
static int a; // (2)
int f( ) { return a; } // (3)
static int f( ) { return a; } // (4)
Select 2 option(s)
Declarations (1) and (3) cannot occur in the same class definition.
Declarations (2) and (4) cannot occur in the same class definition.
Declarations (1) and (4) cannot occur in the same class definition.
Declarations (2) and (3) cannot occur in the same class definition.
Declarations (1) and (2) cannot occur in the same class definition.
17.
Question: Complete the following code by inserting declaration for stateCitiesMap:
//Insert line of code here
List cities = new ArrayList();
cities.add("New York");
cities.add("Albany");
stateCitiesMap.put("NY", cities);
Select 2 option(s)
18.
Question: Given:
Stream names = Stream.of("Sarah Adams", "Suzy Pinnell", "Paul Basgall");
Stream firstNames = //INSERT CODE HERE
Which of the following options will correctly assign a stream of just first names to firstNames?
Select 1 option(s)
names.map(e->e.split(" ")[0]);
names.reduce(e->e.split(" ")[0]);
names.filter(e->e.split(" ")[0]);
names.forEach(e->e.split(" ")[0]);
None
19.
Question: What will the following code fragment print when compiled and run?
Locale myloc = new Locale.Builder().setLanguage("hinglish").setRegion("IN").build(); //L1
ResourceBundle msgs = ResourceBundle.getBundle("mymsgs", myloc);
Enumeration en = msgs.getKeys();
while(en.hasMoreElements()){
String key = en.nextElement();
String val = msgs.getString(key);
System.out.println(key+"="+val);
}
Assume that only the following two properties files (contents of the file is shown below the name of the file) are accessible to the code.
1. mymsgs_hinglish_US.properties
okLabel=OK
cancelLabel=Cancel
2. mymsgs_hinglish_UK.properties
okLabel=YES
noLabel=NO
Select 1 option(s)
It will not compile due to line L1.
It will not print anything.
okLabel=OK
cancelLabel=Cancel
okLabel=YES
noLabel=NO
It will throw an exception at run time.
None
20.
Question: What can be inserted at //2 so that 6 will be printed by the following code?
AtomicInteger ai = new AtomicInteger(5);
//2 INSERT CODE HERE
System.out.println(x);
Select 2 option(s)
int x = ai.increment();
int x = ai.getAndIncrement();
int x = ai + 1;
int x = ai.incrementAndGet();
int x = ai.addAndGet(1);
int x = ai.getAndSet(6);
21.
Question: Which of the following statements are correct regarding confidential information?
Select 3 option(s)
Confidential information should not be dumped into exception stack traces and log messages.
User input should be treated as confidential and kept encrypted in all components except where it is actually used.
Confidential data should be readable only within a limited context.
Sensitive information should be purged from memory after use.
22.
Question: Assume the following declarations:
class A{ }
class B extends A{ }
class C extends B{ }
class X{
B getB(){ return new B(); }
}
class Y extends X{
//method declaration here
}
Which of the following methods can be inserted in class Y?
Select 2 option(s)
Public C getB(){ return new B(); }
Protected B getB(){ return new C(); }
C getB(){ return new C(); }
A getB(){ return new A(); }
23.
Question: Given:
import java.io.*;
class TestClass{
public static void main(String[] args) throws Exception{
try(var bfr = new BufferedReader(new InputStreamReader(System.in))){
System.out.println("Enter Number:");
var s = bfr.readLine();
System.out.println("Your Number is : "+s);
}catch(Exception e){
e.printStackTrace();
}
}
}
What will be the output if the above code is executed using the following command:
java TestClass 123
Select 1 option(s)
Enter Number:
(Program is stuck after printing the above)
Enter Number:
Your Number is:123
Enter Number:
Your Number is:TestClass 123
An exception stack trace will be printed.
None
24.
Question: Given:
class Base{
public ArrayList transform(Set list){
//valid code
};
}
class Derived extends Base{
*INSERT CODE HERE*
//valid code
}
}
What can be inserted in the above code?
Select 1 option(s)
public List< Number > transform(Set< Integer > list){
public List< Integer > transform(Set< Integer > list){
public ArrayList< ? super Integer > transform(Set< Integer > list){
public ArrayList
? extends Number
transform(Set
Number
list){
public ArrayList
Number
transform(Set list){
None
25.
Question: What happens when you try to compile and run the following program?
public class CastTest{
public static void main(String args[ ] ){
byte b = -128 ;
int i = b ;
b = (byte) i;
System.out.println(i+" "+b);
}
}
Select 1 option(s)
The compiler will refuse to compile it because i and b are of different types cannot be assigned to each other.
The program will compile and will print -128 and -128 when run .
The compiler will refuse to compile it because -128 is outside the range of values for a byte.
The program will compile and will print 128 and -128 when run .
The program will compile and will print 255 and -128 when run .
None
26.
Question: Given the following command:
javac --module-source-path c:\java\a -d c:\java\b -p c:\java\c -m x.y
Which of the following statements are correct?
Select 1 option(s)
A directory named out will be created under c:\java\b
A directory named x/y will be created under c:\java\b
A directory named x.y will be created under c:\java\c
Class files will be created under c:\java\b\x.y
Class files will be created under c:\java\a
This command is not valid because -classpath option is missing.
None
27.
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
28.
Question: In the following code, after which statement (earliest), the object originally held in s, may be garbage collected ?
1. public class TestClass{
2. public static void main (String args[]){
3. Student s = new Student("Vaishali", "930012");
4. s.grade();
5. System.out.println(s.getName());
6. s = null;
7. s = new Student("Vaishali", "930012");
8. s.grade();
9. System.out.println(s.getName());
10 s = null;
}
}
public class Student{
private String name, rollNumber;
public Student(String name, String rollNumber) {
this.name = name;
this.rollNumber = rollNumber;
}
//valid setter and getter for name and rollNumber follow
public void grade() {
}
}
Select 1 option(s)
It will not be Garbage Collected till the end of the program.
Line 5
Line 6
Line 7
Line 10
None
29.
Question: Given:
List ls = Arrays.asList(1, 2, 3);
Which of the following options will compute the sum of all Integers in the list correctly?
Select 2 option(s)
30.
Question: Identify examples of autoboxing.
Select 3 option(s)
Long l = Long.valueOf(200);
Integer i = 10;
Integer getValue(){ return 2; }
Long getValue(){ return 2; }
System.out.println(2+"");
31.
Question: Which of the following are valid implementations of java.lang.Comparable?
Select 1 option(s)
var cin = new Comparable
Integer
(){
public int compareTo(Integer i1, Integer i2){
return i1.compareTo(i2);
}
};
var cin = new Comparable
Integer
(){
public int compareTo(Integer i1){
return "100".compareTo(""+i1);
}
};
var cin = new Comparable
Integer
(){
int i = 10;
public int compare(Integer i1){
return i1-this.i;
}
};
var cin = new Comparable<Integer>(){
public int compareTo(Integer i1, Integer i2){
return i1 - i2;
}
};
None
32.
Question: Consider the following class definition:
public class TestClass{
public static void main(String[] args){ new TestClass().sayHello(); } //1
public static void sayHello(){ System.out.println("Static Hello World"); } //2
public void sayHello() { System.out.println("Hello World "); } //3
}
What will be the result of compiling and running the class?
Select 1 option(s)
It will print Hello World.
It will print Static Hello World.
Compilation error at line 2.
Compilation error at line 3.
Runtime Error.
None
33.
Question: Which of the following are correct definitions of a repeatable annotation?
Select 1 option(s)
@Repeatable
public @interface Author {
int id() default 0;
String name();
}
@Repeatable(List.class)
public @interface Author {
int id() default 0;
String name();
}
@Repeatable(List<Author>)
public @interface Author {
int id() default 0;
String name();
}
public @interface Authors{
Author[] value();
}
@Repeatable(Authors.class)
public @interface Author {
int id() default 0;
String name();
}
public class Authors{
Author[] values;
}
@Repeatable(Authors.class)
public @interface Author {
int id() default 0;
String name();
}
public class Authors{
List<Author> authors;
}
@Repeatable(Authors.class)
public @interface Author {
int id() default 0;
String name();
}
None
34.
Question: What will the following code print when compiled and run?
public class Onion {
private String data = "skin";
private class Layer extends Onion {
String data = "thegoodpart";
public String getData() {
return data;
}
}
public String getData() {
return new Layer().getData();
}
public static void main(String[] args) {
var o = new Onion();
System.out.println(o.getData());
}
}
Select 1 option(s)
It will print an empty String.
Skin
Thegoodpart
It will not compile.
It will throw an exception at run time.
None
35.
Question: Given:
class Item{
private int id;
private String name;
public Item(int id, String name){
this.id = id;
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String toString(){
return name;
}
}
public class Test {
public static void main(String[] args) {
List l = Arrays.asList(
new Item(1, "Screw"),
new Item(2, "Nail"),
new Item(3, "Bolt")
);
l.stream()
//INSERT CODE HERE
.forEach(System.out::print);
}
}
Which of the following options can be inserted in the above code independent of each other, so that the code will print BoltNailScrew?
Select 2 option(s)
.sorted((a, b)->a.getId().compareTo(b.getId()))
.sorted(Comparator.comparing(a->a.getName())).map((i)->i.getName())
.map((i)->i.getName())
.map((i)->i.getName()).sorted()
36.
Question: Identify examples of auto-unboxing.
Select 2 option(s)
Int getValue(){ return new int[]{ 1 }; }
New ArrayList().add(1);
List.of(1, 2, 3 );
Int ival = optionalInt.get(); //assuming optionalInt is of type Optional
long lv = Integer.valueOf(10);
37.
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+" ");
None of these.
None
38.
Question: 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);
Select 1 option(s)
0
1
2
True
False
None
39.
Question: What will the following statement return?
" hello java guru ".strip();
Select 1 option(s)
The line of code will not compile.
"hellojavaguru"
"hello java guru"
"hello java guru "
None of the above.
None
40.
Question: Consider the following method -
public float parseFloat( String s ){
float f = 0.0f;
try{
f = Float.valueOf( s ).floatValue();
return f ;
}
catch(NumberFormatException nfe){
f = Float.NaN ;
return f;
}
finally{
f = 10.0f;
return f;
}
}
What will it return if the method is called with the input "0.0" ?
Select 1 option(s)
It will not compile.
It will return 10.0
It will return Float.Nan
It will return 0.0
None of the above.
None
41.
Question: What will be the result of attempting to compile the following program?
public class TestClass{
long l1;
public void TestClass(long pLong) { l1 = pLong ; } //(1)
public static void main(String args[]){
TestClass a, b ;
a = new TestClass(); //(2)
b = new TestClass(5); //(3)
}
}
Select 1 option(s)
A compilation error will be encountered at (1), since constructors should not specify a return value.
A compilation error will be encountered at (2), since the class does not have a default constructor.
A compilation error will be encountered at (3).
The program will compile correctly.
It will not compile because parameter type of the constructor is different than the type of value passed to it.
None
42.
Question: Consider the following code:
public class FileCopier {
public static void copy(String records1, String records2) throws IOException {
try (
InputStream is = new FileInputStream(records1);
OutputStream os = new FileOutputStream(records2);) {
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);
}
} catch (IOException | IndexOutOfBoundsException e) {
e = new FileNotFoundException();
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
copy("c:\\temp\\test1.txt", "c:\\temp\\test2.txt");
}
}
Assuming appropriate import statements and the existence of both the files, what will happen when the program is compiled and run?
Select 1 option(s)
The program will not compile because the try statement is used incorrectly.
The program will not compile because the catch clause is used incorrectly.
The program will not compile because the line e = new FileNotFoundException(); in catch block is invalid.
The program will not compile because the line e.printStackTrace(); in catch block is invalid.
It will compile and run without any error or exception.
It will compile but will throw an exception when run.
None
43.
Question: Given:
var sList = new CopyOnWriteArrayList();
Which of the following statements are correct?
Select 1 option(s)
Student class must be Cloneable or Serializable.
Student objects retrieved from sList are thread safe.
Multiple threads can get Student objects from sList but can't add to it in a thread safe manner simultaneously.
Multiple threads can safely add and remove objects from sList simultaneously.
Any code that adds objects to sList must be synchronized but code that gets objects need not be.
If a thread tries to add an object to it while another is iterating through the list, the second thread may get ConcurrentModificationException.
You cannot add null to sList.
None
44.
Question: Given:
public class Device implements AutoCloseable{
boolean open = false;
public Device(){
open = true;
}
public String read() throws IOException{
throw new IOException("Can't read!");
}
public boolean isOpened(){
return open;
}
public void close(){
open = false;
System.out.println("Device closed");
}
public static void main(String[] args) {
Device d1 = new Device();
try(d1;
Device d2 = new Device();
Device d3 = new Device()){
d2.read();
}catch(Exception e){
System.out.println("Got Exception "+e.getMessage());
}
}
}
What is the status of Device objects at the end of the try/catch blocks?
Select 1 option(s)
All three will be closed.
D1 and d3 will be closed but d2 will remain open.
D1 and d2 will be closed but d3 will remain open.
D2 will be closed but d1 and d3 will remain open.
All three will remain opened.
Compilation failure.
None
45.
Question: What will be the result of attempting to compile and run the following program?
public class TestClass{
public static void main(String args[]){
Exception e = null;
throw e;
}
}
Select 1 option(s)
The code will fail to compile.
The program will fail to compile, since it cannot throw a null.
The program will compile without error and will throw an Exception when run.
The program will compile without error and will throw java.lang.NullPointerException when run
The program will compile without error and will run and terminate without any output.
None
46.
Question: Given:
String[] p = {"1", "2", "3" };
Which of the following lines of code is/are valid?
Select 1 option(s)
None
47.
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
48.
Question: Given:
class Base{
public List transform(Set list){
//valid code
};
}
class Derived extends Base{
*INSERT CODE HERE*
//valid code
}
}
What can be inserted in the above code?
Select 2 option(s)
public List< String > transform(Set< String > list){
public List
Object
transform(Set
CharSequence
list){
public ArrayList
CharSequence
transform(Set
CharSequence
list){
public List
StringBuilder
transform(Set
CharSequence
id){
public List< Integer > transform(TreeSet< CharSequence > id){
public ArrayList< String > transform(Set< String > id){
49.
Question: What will the following code print when compiled and run?
BiPredicate bip = (s, i)-> s.length()>i; //1
BiFunction bif = (s, i)-> { //2
if(bip.test(s, i)){ //3
return s.substring(0, i);
}
else return s;
};
String str = bif.apply("hello world", 5); //4
System.out.println(str);
Select 1 option(s)
hello
compilation failure at //1.
compilation failure at //2.
compilation failure at //3.
compilation failure at //4.
None
50.
Question: Which statements can be inserted at line 1 in the following code to make the program write x on the standard output when run?
public class AccessTest{
String a = "x";
static char b = 'x';
String c = "x";
class Inner{
String a = "y";
String get(){
String c = "temp";
// Line 1
return c;
}
}
AccessTest() {
System.out.println( new Inner().get() );
}
public static void main(String args[]) { new AccessTest(); }
}
Select 3 option(s)
c = c;
c = this.a;
c = ""+AccessTest.b;
c = AccessTest.this.a;
c = ""+b;
51.
Question: Your application was developed and packaged on the Java 8 platform as a jar file. It consists of the following packages:
com.abc.stocks
com.abc.stocks.valuation
com.abc.stocks.analytics
com.abc.bonds
com.abc.bonds.valuation
com.abc.bonds.analytics
com.abc.derivatives
com.abc.derivatives.valuation
com.abc.derivatives.analytics
You are now trying to modularize it into three different modules. Which of the following module descriptions could potentially be valid?
Select 1 option(s)
module com.abc.stocks{
provides com.abc.stocks.analytics;
}
module com.abc.bonds{
provides com.abc.bonds.analytics;
}
module com.abc.derivatives{
provides com.abc.derivatives.analytics;
}
module com.abc.stocks{
exports com.abc.stocks.analytics;
}
module com.abc.bonds{
exports com.abc.bonds.analytics;
}
module com.abc.derivatives{
exports com.abc.derivatives.analytics;
}
module com.abc.stocks{
opens com.abc.stocks.analytics;
}
module com.abc.bonds{
opens com.abc.bonds.analytics;
}
module com.abc.derivatives{
opens com.abc.derivatives.analytics;
}
module com.abc.stocks{
uses com.abc.stocks.valuation;
uses com.abc.stocks.analytics;
}
module com.abc.bonds{
uses com.abc.bonds.valuation;
uses com.abc.bonds.analytics;
}
module com.abc.derivatives{
uses com.abc.derivatives.valuation;
uses com.abc.derivatives.analytics;
}
None
52.
Question: Given the following exception classes:
class MyException extends Exception{}
class MyException1 extends MyException{}
class MyException2 extends MyException{}
class MyException3 extends MyException2{}
and the following code:
try{
//code that could potentially throw any of the above mentioned exceptions
}
INSERT CODE HERE
Which of the following options can be inserted in the above code?
Select 1 option(s)
catch(MyException|MyException3 e){ }
catch(MyException3 me3){ }
catch(Exception e){ }
catch(MyException2 me2){ }
catch(MyException3 me3){ }
catch(Throwable t){ }
catch(MyException3 me3){ }
catch(MyException|MyException1|MyException2|MyException3 e){ }
None
53.
Question: Given:
StringBuilder sb = new StringBuilder("asdf");
Which of the following code fragments will print true?
Select 1 option(s)
String str1 = sb.toString();
String str2 = sb.toString();
System.out.println(str1 == str2);
String str1 = sb.toString();
String str2 = str1;
System.out.println(str1 == str2);
String str1 = sb.toString();
System.out.println(str1 == sb);
System.out.println(sb == new StringBuilder(sb));
None
54.
Question: What will the following code print ?
class Test{
public static void main(String[] args){
int k = 1;
int[] a = { 1 };
k += (k = 4) * (k + 2);
a[0] += (a[0] = 4) * (a[0] + 2);
System.out.println( k + " , " + a[0]);
}
}
Select 1 option(s)
It will not compile.
4 , 4
25 , 25
13 , 13
None of the above.
None
55.
Question: Given:
class Booby{
}
class Dooby extends Booby{
}
class Tooby extends Dooby{
}
and the following declarations:
List bV = null;
List tV = null;
Which of the following statements will compile without any error?
Select 1 option(s)
bV.add( tV.get(0) );
tV.add( bV.get(0) );
bV = tV;
tV = bV;
None of the above.
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