Skip to content
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Java Test 22 – 2024
Welcome to your Java Test 22 - 2024
Name
Email
Phone
Q1. Given:
package loops;
public class JustLooping {
private int j;
void showJ(){
while(j<=5){
for(int j=1; j <= 5;){
System.out.print(j+" ");
j++;
}
j++;
}
}
public static void main(String[] args) {
new JustLooping().showJ();
}
}
What is the result?
You had to select 1 option(s)
It will not compile.
It will print 1 2 3 4 5 five times.
It will print 1 3 5 five times.
It will print 1 2 3 4 5 once.
It will print 1 2 3 4 5 six times.
None
Q2. Given the following code for Book class:
record Book(String title, String isbn){
//insert code here
}
What of the following options illustrates correct usage of instanceof with pattern matching?
You had to select 1 option(s)
None
Q3. Consider the following code :
public class TestClass extends Thread
{
class Runner implements Runnable
{
public void run()
{
var t = new Thread[5];
for(int i=0; i<t.length; i++) System.out.println(t[i]);
}
}
public static void main(String args[]) throws Exception
{
var tc = new TestClass();
new Thread( tc.new Runner() ).start();
}
}
How many Thread objects are created by the above program when it is compiled and run?
You had to select 1 option(s)
1
2
6
7
None, because the program will not compile.
None
Q4. Consider the following code:
class A {
public void doA(int k) throws Exception { // 0
for(int i=0; i< 10; i++) {
if(i == k) throw new Exception("Index of k is "+i); // 1
}
}
public void doB(boolean f) { // 2
if(f) {
doA(15); // 3
}
else return;
}
public static void main(String[] args) { // 4
A a = new A();
a.doB(args.length>0); // 5
}
}
Which of the following statements are correct?
You had to select 1 option(s)
This will compile and run without any errors or exception.
This will compile if throws Exception is added at line //2
This will compile if throws Exception is added at line //4
This will compile if throws Exception is added at line //2 as well as //4
This will compile if line marked // 1 is enclosed in a try - catch block.
None
Q5. Given that Book is a valid class with appropriate constructor and getPrice method that returns a double, what can be inserted at //1 so that it will sum the price of all the books that are priced greater than 5.0?
List books = Arrays.asList(
new Book("Gone with the wind", 10.0),
new Book("Atlas Shrugged", 10.0),
new Book("Freedom at Midnight", 5.0),
new Book("Gone with the wind", 5.0)
);
//1 INSERT CODE HERE
System.out.println(sum);
You had to select 2 option(s)
Q6. What will the following code print?
public class Test{
public int luckyNumber(int seed){
if(seed > 10) return seed%10;
int x = 0;
try{
if(seed%2 == 0) throw new Exception("No Even no.");
else return x;
}
catch(Exception e){
return 3;
}
finally{
return 7;
}
}
public static void main(String args[]){
int amount = 100, seed = 6;
switch( new Test().luckyNumber(6) ){
case 3: amount = amount * 2;
case 7: amount = amount * 2;
case 6: amount = amount + amount;
default :
}
System.out.println(amount);
}
}
You had to select 1 option(s)
It will not compile.
It will throw an exception at runtime.
800
200
400
None
Q7. What will the following code print?
public class BreakTest{
public static void main(String[] args){
int i = 0, j = 5;
lab1 : for( ; ; i++){
for( ; ; --j) if( i >j ) break lab1;
}
System.out.println(" i = "+i+", j = "+j);
}
}
You had to select 1 option(s)
i = 1, j = -1
i = 1, j = 4
i = 0, j = 4
i = 0, j = -1
It will not compile.
None
Q8. 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?
You had to 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
Q9. What changes can be done to the following code so that it will compile and run without an exception?
List keys = List.of("a"); //1
keys.add("b"); //2
Map map = Map.of(); //3
int i = 0;
for(var key : keys){
map.put(key, "----");
}
System.out.println(keys+" "+map.size());
You had to select 1 option(s)
No change is necessary; it will print 2 2.
No change is necessary; it will print 2 1.
Remove //2
Remove //2 and change Map.of() in //3 to new TreeMap().
None
Q10. Given the following contents of module-info.java,
module enthu.finance{
exports com.enthu.Reports to com.enthu.tax;
requires transitive enthu.utils;
}
Select correct statements.
You had to select 1 option(s)
Which ever module requires enthu.finance, must require enthu.utils as well.
The enthu.finance module requires all modules required by enthu.utils.
The enthu.finance module requires only those modules that are required by enthu.utils but does not require enthu.utils itself.
Only classes from the com.enthu.tax module are allowed to read classes in the com.enthu.Reports package.
The enthu.finance module exports only those classes that are used by the com.enthu.tax module.
This is an invalid module definition because exports-to and requires-transitive clauses cannot be used together.
Only non-sealed classes from com.enthu.Reports are exported.
None
Q11. Given:
public List getList(){
*INSERT CODE HERE*
}
What can be inserted in the above code?
You had to select 3 option(s)
Q12. You have been given an array of objects and you need to process this array as follows -
1. Call a method on each object from first to last one by one.
2. Call a method on each object from last to first one by one.
3. Call a method on only those objects at even index (0, 2, 4, 6, etc.)
Which of the following are correct?
You had to select 1 option(s)
Enhanced for loops can be used for all the three tasks.
Enhanced for loop can be used for only the first task. For the rest, standard for loops can be used.
Standard for loops can be used for tasks 1 and 2 but not 3.
All the tasks can be performed either by using only standard for loops or by using only enhanced for loops.
Neither standard for loops nor enhanced for loops can be used for all three tasks.
None
Q13. Which of the given lines can be inserted at //1 of the following program ?
public class TestClass
{
public static void main(String[] args)
{
short s = 9;
//1
}
}
You had to select 2 option(s)
Short k = new Short(9);
System.out.println(k instanceof Short);
System.out.println(s instanceof Short);
Short k = 9;
System.out.println( k instanceof s);
int i = 9;
System.out.println(s == i);
Boolean b = s instanceof Number;
Short k = 9; Integer i = 9;
System.out.println(k == i);
Integer i = 9;
System.out.println( s == i );
Q14. What, if anything, is wrong with the following code?
interface T1{
}
interface T2{
int VALUE = 10;
void m1();
}
interface T3 extends T1, T2{
public void m1();
public void m1(int x);
}
You had to select 1 option(s)
T3 cannot implement both T1 and T2 because it leads to ambiguity.
There is nothing wrong with the code.
The code will work fine only if VALUE is removed from T2 interface.
The code will work fine only if m1() is removed from either T2 and T3.
None of the above.
None
Q15. Consider the following code:
class A
{
}
public class TestClass
{
public class A
{
public void m() { }
}
class B extends A
{
B(){ m(); }
}
public static void main(String args[])
{
new TestClass().new A() { public void m() { } }; //1
var tc = new TestClass();
//insert call to A's m() here
}
}
You had to select 4 option(s)
This program will not compile.
class created inside the main method at //1 is static.
class created inside the main method at //1 is final.
Objects of class B cannot be created inside the main method just by doing "new B()"
new TestClass().new A().m(); can be inserted in main to invoke A's m().
new A().m(); can be inserted in main to invoke A's m().
tc.new A().m(); can be inserted in main to invoke A's m().
Q16. Given:
public class Book{
private String title;
private Double price;
public Book(String title, Double price){
this.title = title;
this.price = price;
}
//accessor methods not shown
What will the following code print when compiled and run?
Book b1 = new Book("Java in 24 hrs", null);
DoubleSupplier ds1 = b1::getPrice;
System.out.println(b1.getTitle()+" "+ds1.getAsDouble());
You had to select 1 option(s)
Java in 24 hrs null
Java in 24 hrs 0.0
Java in 24 hrs
It will throw a NullPointerException.
It will not compile.
None
Q17. Given:
module broker{
exports org.broker.api;
}
The broker module contains org.broker.api.Installer interface, which is implemented by com.foo.AppInstaller class of com.foo module.
Which of the following is a valid module definition for com.foo module?
You had to select 1 option(s)
module com.foo{
exports broker;
}
module com.foo{
provider broker;
}
module com.foo{
requires broker;
provides org.broker.api;
}
module com.foo{
requires broker;
exports com.foo;
provides org.broker.api.Installer with com.foo.AppInstaller;
}
module com.foo{
exports com.foo;
provides org.broker.api.Installer with com.foo.AppInstaller;
}
None
Q18. 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?
You had to select 1 option(s)
//1 and //2
//2 and //5
//1 //2 and //5
//1 and //3
//1 //3 and //4
None
Q19. Given:
int expr1 = 3 + 5 * 9 - 7;
int expr2 = 3 + (5 * 9) - 7;
int expr3 = 3 + 5 * (9 - 7);
int expr4 = (3 + 5) * 9 - 7;
Which of the above variables will have the value 45?
You had to select 1 option(s)
expr1
expr2
expr3
expr4
None of them.
None
Q20. 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?
You had to 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
Q21. Given:
public class Triangle{
public int base;
public int height;
public double area;
public Triangle(int base, int height){
this.base = base; this.height = height;
updateArea();
}
void updateArea(){
area = base*height/2;
}
public void setBase(int b){ base = b; updateArea(); }
public void setHeight(int h){ height = h; updateArea(); }
}
The above class needs to protect an invariant on the "area" field (meaning, the value of the ///area/// field should always be equal to the value computed using the formula for area of a triangle). Which three members must have the public access modifiers removed to ensure that the invariant is maintained?
You had to select 3 option(s)
the base field
the height field
the area field
the Triangle constructor
the setBase method
the setHeight method
Q22. 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);
You had to select 1 option(s)
1 3
-1 3
-2 3
-2 -3
The code will not compile.
None
Q23. What will the following code print when compiled and run?
public class TestClass {
public static void main(String[] args) {
String s = "blooper";
StringBuilder sb = new StringBuilder(s);
s.append("whopper");
sb.append("shopper");
System.out.println(s);
System.out.println(sb);
}
}
You had to select 1 option(s)
blooper and bloopershopper
blooperwhopper and bloopershopper
blooper and blooperwhoppershopper
It will not compile.
None
Q24. Identify correct statement(s) about the following code:
var value = 1,000,000; //1
switch(value){
case 1_000_000 - > { //2
System.out.println("A million 1");
break; //3
}
case 1000000 - > { //4
System.out.println("A million 2");
}
}
You had to select 1 option(s)
It will print A million 1 when compiled and run.
It will print A million 2 when compiled and run.
Compilation fails only at line //1
Compilation fails only at line //2
Compilation fails only at line //4
Compilation fails at line //1 and //4
Compilation fails at line //1, //3, and //4
None
Q25. 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?
You had to 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
Q26. What will the following code print when run?
public class Test{
static String j = "";
public static void method( int i){
try{
if(i == 2){
throw new Exception();
}
j += "1";
}
catch (Exception e){
j += "2";
return;
}
finally{
j += "3";
}
j += "4";
}
public static void main(String args[]){
method(1);
method(2);
System.out.println(j);
}
}
You had to select 1 option(s)
13432
13423
14324
12434
12342
None
Q27. What will the following code print?
Path p1 = Paths.get("/photos/vacation");
Path p2 = Paths.get("/yellowstone");
System.out.println(p1.resolve(p2)+" "+p1.relativize(p2));
You had to select 1 option(s)
yellowstone ../../yellowstone
/yellowstone ../../yellowstone
/yellowstone /yellowstone
/yellowstone yellowstone
None
Q28. Given the following class, which statements can be inserted at line 1 without causing the code to fail compilation?
public class TestClass{
int a;
int b = 0;
static int c;
public void m(){
int d;
int e = 0;
// Line 1
}
}
You had to select 4 option(s)
a++;
b++;
c++;
d++;
e++;
Q29. Given:
List dList = Arrays.asList(10.0, 12.0);
dList.forEach(x->{ x = x + 10; });
dList.forEach(x->System.out.println(x));
What will it print when compiled and run?
You had to select 1 option(s)
A compilation error will occur.
10.0
12.0
20.0
22.0
It will compile but throw an exception at run time.
None
Q30. Given the following method code:
public void myMethod() throws MyException {
//method code
}
You had to select 1 option(s)
If the throws MyException clause is removed from the method and if the method fails to compile, then MyException must be an unchecked exception.
If the throws MyException clause is removed from the method and if the method fails to compile, then MyException must be extending RuntimeException.
A method that calls myMethod must wrap the call in a try block.
The code in myMethod can throw only MyException.
If MyException class is made to extend RuntimeException, there would be no impact on myMethod.
None
Q31. Which of the following commands can be used to run a class named com.foo.Bar, which is part of a module named foo.bar packaged in foobar.jar
(Assume that the jar file is located in the current directory.)
You had to select 1 option(s)
java --classpath foobar.jar --module foo.bar/com.foo.Bar
java --module foobar.jar foo.bar/com.foo.Bar
java --classpath foobar.jar --module-path foo.bar/com.foo.Bar
java --module-path foobar.jar com.foo.Bar
java --module-path foobar.jar --module foo.bar/com.foo.Bar
None
Q32. What will the following code print when compiled and run?
(Assume that MySpecialException is an unchecked exception.)
1. public class ExceptionTest {
2. public static void main(String[] args) {
3. try {
4. doSomething();
5. } catch (MySpecialException e) {
6. System.out.println(e);
7. }
8. }
9.
10. static void doSomething() {
11. int[] array = new int[4];
12. array[4] = 4;
13. doSomethingElse();
14. }
15.
16. static void doSomethingElse() {
17. throw new MySpecialException("Sorry, can't do something else");
18. }
}
You had to select 1 option(s)
It will not compile.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at ExceptionTest.doSomething(ExceptionTest.java:12)
at ExceptionTest.main(ExceptionTest.java:4)
Exception in thread "main" MySpecialException: 4
at ExceptionTest.doSomethingElse(ExceptionTest.java:17)
at ExceptionTest.doSomething(ExceptionTest.java:12)
at ExceptionTest.main(ExceptionTest.java:4)
Exception in thread "main" MySpecialException: Sorry, can't do something else
at ExceptionTest.doSomethingElse(ExceptionTest.java:17)
at ExceptionTest.doSomething(ExceptionTest.java:12)
at ExceptionTest.main(ExceptionTest.java:4)
Exception in thread "main" MySpecialException: Sorry, can't do something else
at ExceptionTest.doSomethingElse(ExceptionTest.java:17)
at ExceptionTest.doSomething(ExceptionTest.java:13)
at ExceptionTest.main(ExceptionTest.java:4)
None
Q33. What will the following code print?
List str = Arrays.asList(1,2, 3, 4 );
str.stream().filter(x->{
System.out.print(x+" ");
return x>2;
});
You had to select 1 option(s)
1 2 3 4
1 2 3 4 4
4
It will not print anything.
None
Q34. The following code snippet will print true.
String str1 = "one";
String str2 = "two";
System.out.println( str1.equals(str1=str2) );
You had to select 1 option(s)
True
False
None
Q35. Given:
public class Book {
private int id;
private String title;
private String genre;
private String author;
private double price;
//constructors and accessors not shown
}
Assuming that books is a List of Book objects, what can be inserted in the code below at DECLARATION and EXPRESSION so that it will classify the books by genre and then also by author?
DECLARATION classified = null;
classified = books.stream().collect(Collectors.groupingBy(
EXPRESSION
));
System.out.println(classified);
You had to select 1 option(s)
None
Q36. Given:
StringBuilder sb = new StringBuilder("asdf");
Which of the following code fragments will print true?
You had to 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
Q37. Given:
class OverloadingTest{
void m1(int x){
System.out.println("m1 int");
}
void m1(float x){
System.out.println("m1 float");
}
void m1(String x){
System.out.println("m1 String");
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
OverloadingTest ot = new OverloadingTest();
ot.m1(1.0);
}
}
What will be the output?
You had to select 1 option(s)
It will fail to compile.
m1 int
m1 float
m1 String
None
Q38. Consider the following
public class TestClass {
public static void main(String[] args) {
TestClass tc = new TestClass();
tc.myMethod();
}
public void myMethod() {
yourMethod();
}
public void yourMethod() {
throw new Exception();
}
}
What changes can be done to make the above code compile?
You had to select 1 option(s)
Change declaration of main to :
public static void main(String[] args) throws Exception
Change declaration of myMethod to
public void myMethod throws Exception
Change declaration of yourMethod to
public void yourMethod throws Exception
Change declaration of main and yourMethod to :
public static void main(String[] args) throws Exception and
public void yourMethod throws Exception
Change declaration of all the three method to include throws Exception.
None
Q39. What will be the result of compiling and running the following program ?
class NewException extends Exception {}
class AnotherException extends Exception {}
public class ExceptionTest{
public static void main(String [] args) throws Exception{
try{
m2();
}
finally{ m3(); }
}
public static void m2() throws NewException{ throw new NewException(); }
public static void m3() throws AnotherException{ throw new AnotherException(); }
}
You had to select 1 option(s)
It will compile but will throw AnotherException when run.
It will compile but will throw NewException when run.
It will compile and run without throwing any exceptions.
It will not compile.
None of the above.
None
Q40. Given:
abstract class Vehicle{ }
interface Drivable{ }
class Car extends Vehicle implements Drivable{ }
class SUV extends Car { }
Which of the following options will compile?
You had to select 2 option(s)
Q41. Identify valid methods:
Assume that Shape is a valid non-final class.
You had to select 2 option(s)
Q42. What will the following code most likely print when compiled and run?
List names = Arrays.asList("greg", "dave", "don", "ed", "fred" );
Map data = names.stream().collect(Collectors.groupingBy(
String::length,
Collectors.counting()) );
System.out.println(data.values());
You had to select 1 option(s)
[1, 1, 3]
[1, 2, 3]
[2, 3, 4]
["greg", "dave", "don", "ed", "fred"]
The data variable should be declared of type Map for the code to compile.
None
Q43. Assume that dt refers to a valid java.util.Date object and that df is a reference variable of class DateFormat.
Which of the following code fragments will print the country and the date in the correct local format?
You had to select 1 option(s)
Locale l = Locale.getDefault();
DateFormat df = DateFormat.getDateInstance(l);
System.out.println(l.getCountry()+" "+ df.format(dt));
Locale l = Locale.getDefault();
DateFormat df = DateFormat.getDateInstance();
System.out.println(l.getCountry()+" "+ df.format(dt, l));
Locale l = Locale.getDefault();
DateFormat df = DateFormat.getDateInstance();
System.out.println(l.getCountry()+" "+ df.format(dt));
Locale l = new Locale();
DateFormat df = DateFormat.getDateInstance();
System.out.println(l.getCountry()+" "+ df.format(dt));
None
Q44. Given that c:\temp\pathtest is a directory that contains several directories. Each sub directory contains several files but there is exactly one regular file named test.txt within the whole directory structure.
Which of the given options can be inserted in the code below so that it will print complete path of test.txt?
try{
Stream s = null;
INSERT CODE HERE
s.forEach(System.out::println);
}catch(IOException ioe){
ioe.printStackTrace();
}
You had to select 1 option(s)
None
Q45. Given the following source code, which of the lines that are commented out may be reinserted without introducing errors?
abstract class Bang{
// abstract void f(); // LINE 0
final void g(){}
// final void h(){} // LINE 1
protected static int i;
private int j;
}
final class BigBang extends Bang{
// BigBang(int n) { m = n; } // LINE 2
public static void main(String args[]){
Bang mc = new BigBang();
}
// @Override // LINE 3
void h(){}
// void k(){ i++; } // LINE 4
// void l(){ j++; } // LINE 5
int m;
}
Consider each line independently.
You had to select 1 option(s)
abstract void f( ) ; //(0)
final void h( ) { } //(1)
BigBang(int n) { m = n; } //(2)
@Override //(3)
Since there is no h() method in the superclass, @Override is invalid here.
void k( ) { i++; } //(4)
void l( ) { j++; } //(5)
None
Q46. Given:
What will be the result?
You had to 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
Q47. Given that listOfWords points to a List of words, which of the following code snippets will create a list of two letter words?
You had to select 3 option(s)
Q48. Given:
public class Book {
private String title;
private String genre;
public Book(String title, String genre){
this.title = title; this.genre = genre;
}
//accessors not shown
}
and the following code:
List books = Arrays.asList(
new Book("Gone with the wind", "Fiction"),
new Book("Bourne Ultimatum", "Thriller"),
new Book("The Client", "Thriller")
);
Reader r = b->{
System.out.println("Reading book "+b.getTitle());
};
books.forEach(x->r.read(x));
What would be a valid definition of Reader for the above code to compile and run without any error or exception?
You had to select 2 option(s)
abstract class Reader{
abstract void read(Book b);
}
abstract class Reader{
void read(Book b);
}
@FunctionalInterface
interface Reader{
void read(Book b);
default void unread(Book b){ }
}
interface Reader{
default void read(Book b){ }
void unread(Book b);
private void doSomethingelse(){ }
}
@FunctionalInterface
interface Reader{
default void read(Book b){ System.out.println("Default read");};
}
Q49. Given :
import java.util.*;
class MyStringComparator implements Comparator
{
public int compare(Object o1, Object o2)
{
int s1 = ((String) o1).length();
int s2 = ((String) o2).length();
return s1 - s2;
}
}
and
static String[] sa = { "d", "bbb", "aaaa" };
Select correct statements.
You had to select 2 option(s)
This is not a valid Comparator implementation.
Arrays.binarySearch(sa, "cc", new MyStringComparator()); will return -2.
Arrays.binarySearch(sa, "c", new MyStringComparator()); will return 0.
Arrays.binarySearch(sa, "c", new MyStringComparator()); will return -1.
Arrays.binarySearch(sa, "c", new MyStringComparator()); will throw an exception.
Q50. Given:
public static void main(String[] args) {
String str = "10";
int iVal = 0;
Double dVal = 0.0;
try{
iVal = Integer.parseInt(str, 2); //1
if((dVal = Double.parseDouble(str)) == iVal){ //2
System.out.println("Equal");
}
}catch(NumberFormatException e){
System.out.println("Exception in parsing");
}
System.out.println(iVal+" "+dVal);
}
What is the result?
You had to select 1 option(s)
Compilation failure at //1.
Compilation failure at //2.
Exception in parsing
0 0.0
Exception in parsing
10 0.0
Equal
10 10.0
10 10.0
2 10.0
Exception in parsing
2 0.0
None
Q51. Identify the right declaration for 'box' for the following code.
import java.util.*;
class Dumper {
// declaration for box
public void dumpStuff(){
for(List l : box.values()){
System.out.println(l);
}
}
}
You had to select 2 option(s)
Q52. What will the following program print when run?
// Filename: TestClass.java
public class TestClass{
public static void main(String args[] ){ A b = new B("good bye"); }
}
class A{
A() { this("hello", " world"); }
A(String s) { System.out.println(s); }
A(String s1, String s2){ this(s1 + s2); }
}
class B extends A{
B(){ super("good bye"); };
B(String s){ super(s, " world"); }
B(String s1, String s2){ this(s1 + s2 + " ! "); }
}
You had to select 1 option(s)
It will print "good bye".
It will print "hello world".
It will print "good bye world".
It will print "good bye" followed by "hello world".
It will print "hello world" followed by "good bye".
None
Q53. Given that daylight Savings Time starts on March 13th, 2022 at 2 AM in US/Eastern time zone. (As a result, 2 AM becomes 3 AM. In other words, 1 minute after 1.59AM, the clock goes to 3.00 AM instead of 2 AM), what will the following code print?
LocalDateTime ld1 = LocalDateTime.of(2022, Month.MARCH, 13, 2, 0);
ZonedDateTime zd1 = ZonedDateTime.of(ld1, ZoneId.of("US/Eastern"));
LocalDateTime ld2 = LocalDateTime.of(2022, Month.MARCH, 13, 3, 0);
ZonedDateTime zd2 = ZonedDateTime.of(ld2, ZoneId.of("US/Eastern"));
long x = ChronoUnit.HOURS.between(zd1, zd2);
System.out.println(x);
You had to select 1 option(s)
1
-1
0
2
-2
It will not compile.
None
Q54. Given that New York is 3 hours ahead of Los Angeles, what will the following code print?
LocalDateTime ldt = LocalDateTime.of(2022, 12, 02, 6, 0, 0);
ZonedDateTime nyZdt = ldt.atZone(nyZone);
ZonedDateTime laZdt = ldt.atZone(laZone);
Duration d = Duration.between(nyZdt, laZdt);
System.out.println(d);
You had to select 1 option(s)
PT0S
PT3H
PT-3H
PT0H
None
Q55. What will be the output when the following code is compiled and run?
class Person implements Serializable{
String name;
Person(String name){
this.name = name;
System.out.print("Person ");
}
public String toString(){ return name; }
}
class Student extends Person{
String school;
public Student(String name, String school){
super(name);
this.school = school;
System.out.print("Student ");
}
public String toString(){
return super.toString()+" "+school;
}
}
public class SerialTest {
public static void main(String[] args) throws Exception {
Person p = new Student("Bob Dylan", "NYU");
try(
ObjectOutputStream oos = new ObjectOutputStream(
new FileOutputStream("c:\\temp\\student.ser"));
ObjectInputStream ois = new ObjectInputStream(
new FileInputStream("c:\\temp\\student.ser"));
){
oos.writeObject(p);
oos.flush();
System.out.println((Person)ois.readObject());
}
}
}
You had to select 1 option(s)
Person Student null NYU
Person Student Student Person Bob Dylan NYU
Student Person Person Student Bob Dylan NYU
Person Student Person Student null null
Person Student Bob Dylan NYU
Person Student null null
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