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 12 – 2024
Welcome to your Java Test - 12 - 2024
Name
Email
Phone
Q1. Given:
module abc.blogger {
requires serviceapi;
provides api.BloggerService with abc.SimpleBlogger;
}
Which of the following code fragments appearing in another module correctly loads a service provider that implements api.BloggerService?
You had to select 1 option(s)
None
Q2. What will the following code print?
int[] ia1 = { 0, 1, 4, 5};
int[] ia2 = { 0, 1, 1, 5, 6};
int x = Arrays.compare(ia1, ia2);
int y = Arrays.mismatch(ia1, ia2);
System.out.println(x+" "+y);
You had to select 1 option(s)
1 2
2 2
1 3
-1 2
-1 -2
None
Q3. What will be the contents of s1 and s2 when the control reaches the println statement in the main method of the following program?
import java.util.*;
public class TestClass{
public static void main(String args[]){
Stack s1 = new Stack ();
Stack s2 = new Stack ();
processStacks (s1, s2);
System.out.println (s1 + " "+ s2);
}
public static void processStacks(Stack x1, Stack x2){
x1.push (Integer.valueOf("100"));
//assume that the method push adds the passed object to the stack.
x2 = x1;
}
}
Note:[] is used in the options below to denote each element of the Stack.
You had to select 1 option(s)
[100] [100]
[100] []
[] [100]
[] []
None
Q4. What will the following program print?
class Test{
public static void main(String[] args){
var i = 4;
int ia[][][] = new int[i][i = 3][i];
System.out.println( ia.length + ", " + ia[0].length+", "+ ia[0][0].length);
}
}
You had to select 1 option(s)
It will not compile.
3, 4, 3
3, 3, 3
4, 3, 4
4, 3, 3
None
Q5. What will the following code print when compiled and run?
int [] [] array = {{0}, {0, 1}, {0, 1, 2}, {0, 1, 2, 3}, {0, 1, 2, 3, 4}};
var arr1 = array[4];
System.out.println (arr1[4][1]);
System.out.println (array[4][1]);
You had to select 1 option(s)
1
1
1
4
4
1
It will not compile.
It will throw ArrayIndexOutOfBoundsException at run time.
It will throw IllegalArgumentException at run time.
None
Q6. 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", 30.0);
Book b2 = new Book("Thinking in Java", null);
Supplier s1 = b1::getPrice;
System.out.println(b1.getTitle()+" "+s1.get());
Supplier s2 = b2::getPrice;
System.out.println(b2.getTitle()+" "+s2.getAsDouble());
You had to select 1 option(s)
Java in 24 hrs 30.0
Java in 24 hrs 30.0
Thinking in Java 0.0
< exception stack trace >
It will not compile.
None
Q7. 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
You had to 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
Q8. Assuming that the directory /works/ocpjp/code exists but /works/ocpjp/code/sample does not exist, what will the following code output?
Path d1 = Paths.get("/works");
Path d2 = d1.resolve("ocpjp/code"); //1
d1.resolve("ocpjp/code/sample"); //2
d1.toAbsolutePath(); //3
System.out.println(d1);
System.out.println(d2);
You had to select 1 option(s)
None
Q9. Identify the correct statements about Java Stream API.
You had to select 1 option(s)
Streams are reusable.
Elements of a stream are mutable.
Streams support aggregate operations.
All Stream operations are lazy.
None
Q10. Given:
public class Movie{
private String title;
private String genre;
public Movie(String title, String genre){
this.title = title;
this.genre = genre;
}
//accessors not shown
}
and
Stream sm = Stream.of( new Movie("a1", "a"),
new Movie("a2", "a"),
new Movie("b1", "b"), new Movie("c1", null));
Which of the following code fragments will get the number of movies that do not belong to any genre (i.e. where genre is null)?
You had to select 1 option(s)
None
Q11. 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?
You had to select 1 option(s)
bV.add( tV.get(0) );
tV.add( bV.get(0) );
bV = tV;
tV = bV;
None of the above.
None
Q12. You want to execute a task that returns a result without blocking. Which of the following types from java.util.concurrent package will be required to achieve this?
You had to select 4 option(s)
Executor
ExecutorService
Executors
Runnable
Callable
Future
Q13. Identify the valid for loop constructs assuming the following declarations:
Object o = null;
Collection c = //valid collection object.
int[][] ia = //valid array
You had to select 2 option(s)
for(o : c){ }
for(final var o2 : c){ }
for(int i : ia) { }
for(Iterator it : c.iterator()){ }
for(int i : ia[0]){ }
Q14. What will the following code print?
List names = Arrays.asList(1, 2, 3); //1
names.forEach(x->x=x+1); //2
names.forEach(System.out::println); //3
You had to select 1 option(s)
1
2
3
2
3
4
It will not compile due to code at //2
It will not compile due to code at //3
None
Q15. What can be inserted in the following code so that it will print [21, 32, 43] ?
List ls = Arrays.asList(11, 22, 33);
//INSERT CODE HERE
ls.replaceAll(func);
System.out.println(ls);
You had to select 1 option(s)
None
Q16. 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
}
You had to select 2 option(s)
Line 10
Line 11
Line 12
Line 15
Line 19
Q17. 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);
}
}
You had to 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
Q18. Given:
public class Book{
String isbn;
String title;
public Book(String isbn, String title){
this.isbn = isbn;
this.title = title;
}
public int compareTo(Book b){
return this.isbn.compareTo(b.isbn);
}
//accessors not shown
}
and the following code snippet:
List books = getBooksByAuthor("Ludlum");
Collections.sort(books, (b1, b2)->b1.getTitle().compareTo(b2.getTitle())); //1
Collections.sort(books); //2
Assuming that getBooksByAuthor is a valid method that returns a List of Books, which of the following statements is/are true?
You had to select 1 option(s)
Compilation failure at //1.
Compilation failure at //2.
Exception at run time because of //1.
Exception at run time because of //2.
Elements in books List will be sorted by title and then by isbn.
None
Q19. Consider the following code :
import java.util.*;
class Request { }
class RequestCollector{
//1 : Insert declaration here
public synchronized void addRequest(Request r){
container.add(r);
}
public synchronized Request getRequestToProcess(){
return container.poll();
}
}
What can be inserted at //1?
You had to select 1 option(s)
None
Q20. What will be the result of attempting to compile and run the following code?
public class InitClass{
public static void main(String args[ ] ){
InitClass obj = new InitClass(5);
}
int m;
static int i1 = 5;
static int i2 ;
int j = 100;
int x;
public InitClass(int m){
System.out.println(i1 + " " + i2 + " " + x + " " + j + " " + m);
}
{ j = 30; i2 = 40; } // Instance Initializer
static { i1++; } // Static Initializer
}
You had to select 1 option(s)
The code will fail to compile since the instance initializer tries to assign a value to a static member.
The code will fail to compile since the member variable x will be uninitialized when it is used.
The code will compile without error and will print 6 40 0 30 5 when run.
The code will compile without error and will print 5, 0, 0, 100, 5 when run.
The code will compile without error and will print 5, 40, 0, 30, 0 when run.
None
Q21. You want to invoke the overridden method (the method in the base class) from the overriding method (the method in the derived class) named m().
Which of the following constructs which will let you do that?
You had to select 1 option(s)
super.m();
super.this();
base.m();
parent.m();
super();
None
Q22. You want to change the default locale for formatting numbers, currency, and percentages. Which of the following statements will achieve that?
You had to select 2 option(s)
Locale.setDefault(Locale.EN_US);
EN_US is not a valid Locale.
Locale.setDefault("en_US");
Locale.setDefault(Locale.Category.FORMAT, Locale.US);
Locale.setDefault(Locale.Category.FORMAT, "en_US");
Locale.setDefault(Locale.US);
Q23. Given:
byte b = 1;
char c = 1;
short s = 1;
int i = 1;
which of the following expressions are valid?
You had to select 3 option(s)
s = b * b ;
i = b + b ;
s *= b ;
c = c + b ;
s += i ;
Q24. Given that classes B1 and B2 extend class A and classes C1, C2 are subclasses of B1.
Further, assume that method public void m1(){ ... } is defined in all of these classes EXCEPT B1 and C1.
class A{
public void m1(){ }
}
class B1 extends A{
}
class B2 extends A{
public void m1(){ }
}
class C1 extends B1{
}
class C2 extends B1{
public void m1(){ }
}
Assume that "objectOfXX" means a variable that points to an object of class XX. So, objectOfC1 means a reference variable that is pointing to an object of class C1.
Which of the following statements are correct?
You had to select 1 option(s)
objectOfC1.m1(); will cause a compilation error.
objectOfC2.m1(); will cause A's m1() to be called.
objectOfC1.m1(); will cause A's m1() to be called.
objectOfB1.m1(); will cause an exception at runtime.
objectOfB2.m1(); will cause an exception at runtime.
None
Q25. What will the following program print?
public class TestClass{
public static void main(String[] args){
var str = "111";
boolean[] bA = new boolean[1];
if( bA[0] ) str = "222";
System.out.println(str);
}
}
You had to select 1 option(s)
111
222
It will not compile as bA[0] is uninitialized.
It will throw an exception at runtime.
None of the above.
None
Q26. Which of the following method definitions will prevent overriding of that method?
You had to select 4 option(s)
public final void m1()
public static void m1()
public static final void m1()
public abstract void m1()
private void m1()
public sealed void m1()
Q27. Given:
enum Coffee
{
ESPRESSO("Very Strong"), MOCHA("Bold"), LATTE("Mild");
public String strength;
Coffee(String strength)
{
this.strength = strength;
}
}
and the statement
System.out.println(Coffee.ESPRESSO);
What can be done so that the above statement will print Very Strong?
You had to select 1 option(s)
Insert the following in Coffee:
public String toString(){ return Coffee.values()[0]; }
Insert the following in Coffee:
String toString(){ return "Very Strong"; }
Insert the following in Coffee:
public String toString(){ return String.valueOf(Coffee.ESPRESSO);}
Insert the following in Coffee:
public String toString(){ return String.valueOf(strength);}
None
Q28. What can be inserted in the following code at //1 so that it will print the number of lines present in the given file?
public void countLines(String filePath) throws Exception{
//1
System.out.println(ref.count());
}
You had to select 2 option(s)
Q29. Assuming that the following code compiles without any error, identify correct statements.
interface Processor {
A process(String str);
}
class ItemProcessor implements Processor{
@Override
public B process(String str){
return new B(str);
}
}
You had to select 2 option(s)
B must be a sub type of A.
A must be a sub type of B.
There need not be any type - sub type relation between A and B or B and A.
B must be final.
B must not be final.
A cannot be abstract.
B cannot be abstract.
Q30. Identify the correct statements about ArrayList?
You had to select 3 option(s)
ArrayList extends java.util.AbstractList.
It allows you to access its elements in random order.
You must specify the class of objects you want to store in ArrayList when you declare a variable of type ArrayList.
ArrayList does not implement RandomAccess.
You can sort its elements using Collections.sort() method.
Q31. Which of the following statements are true?
You had to select 1 option(s)
A synchronized method cannot call another synchronized method in its body.
A thread is allowed to reacquire a lock that it already has. So there will not be a deadlock if a method calls itself. There is a possibility of StackOverflowError if the recursion is deeper than the space avaliable on the stack.
Only non-static member variables are accessible in a synchronized method.
A synchronized method cannot be executed simultaneously by more than one thread on the same object.
A synchronized method cannot call a non-synchronized method in its body.
None
Q32. What will the following code print?
int x = 1;
int y = 2;
int z = x++;
int a = --y;
int b = z--;
b += ++z;
int answ = x>a?y>b?y:b:x>z?x:z;
System.out.println(answ);
You had to select 1 option(s)
0
1
2
-1
-2
-3
None
Q33. What is the result of executing the following fragment of code:
boolean b1 = false;
boolean b2 = false;
if (b2 != b1 = !b2){
System.out.println("true");
}
else{
System.out.println("false");
}
You had to select 1 option(s)
Compile time error.
It will print true.
It will print false.
Runtime error.
It will print nothing.
None
Q34. Given the following code:
import java.util.Arrays;
import java.util.List;
public class TestClass {
public static void main(String[] args) {
List al = Arrays.asList(100, 200, 230, 291, 43);
System.out.println( *INSERT CODE HERE* );
}
}
Which of the following options will correctly print the number of elements that are less than 200?
You had to select 1 option(s)
None
Q35. What will the following code NEVER print when run?
enum SIZE
{
TALL, JUMBO, GRANDE;
}
class CoffeeMug
{
public static void main(String[] args)
{
var hs = new HashSet();
hs.add(SIZE.TALL); hs.add(SIZE.JUMBO); hs.add(SIZE.GRANDE);
hs.add(SIZE.TALL); hs.add(SIZE.TALL); hs.add(SIZE.JUMBO);
for(SIZE s : hs) System.out.print(s+" ");
}
}
You had to select 2 option(s)
GRANDE TALL JUMBO
TALL JUMBO GRANDE
TALL GRANDE JUMBO
TALL JUMBO GRANDE TALL TALL JUMBO
TALL JUMBO GRANDE TALL JUMBO
Q36. Given:
class MyGenericClass{
public String transform(T t){
return t.toString()+"-"+t.hashCode();
}
}
and the following code snippet:
MyGenericClass gc = new MyGenericClass();
System.out.println(gc.transform(1)); //1
System.out.println(gc.transform("hello")); //2
MyGenericClass gcStr = new MyGenericClass();
System.out.println(gcStr.transform(1.1)); //3
What will it print when compiled and run?
You had to select 1 option(s)
None
Q37. Given the follow two module definitions:
module author{
requires serviceapi;
uses api.BloggerService;
}
and
module abc.blogger{
requires serviceapi;
provides api.BloggerService with abc.SimpleBlogger;
}
Identify correct statement(s).
You had to select 2 option(s)
api.BloggerService should be defined in author module.
api.BloggerService should be defined in abc.blogger module.
api.BloggerService should be defined in serviceapi module.
abc.blogger module should be on --module-path while executing the author module but is not required while compiling.
author module should be on --module-path while executing the abc.blogger module but is not required while compiling.
Q38. Consider the following code:
Instant ins = Instant.now();
System.out.println(ins);
Given that the local time where the code is run is 3PM and the local time zone is 2 hours ahead of UTC, what will the above code print?
(Assume that the date is 20th Jan 2022).
You had to select 1 option(s)
2022-01-20T13:00:00.001Z
2022-01-20T15:00:00.001Z
2022-01-20T11:00:00.001Z
2022-01-20T01:00:00.001Z
2022-01-20T03:00:00.001Z
None
Q39. Given the following code:
import java.util.Arrays;
import java.util.List;
public class TestClass {
public static void main(String[] args) {
List al = Arrays.asList("aa", "aaa", "b", "cc", "ccc", "ddd", "a");
//INSERT CODE HERE
System.out.println(count);
}
}
Which of the following options will correctly print the number of elements that will come before the string "c" if the list were sorted alphabetically?
You had to select 1 option(s)
None
Q40. Consider the following code:
import java.util.*;
class Book{ }
class TextBook extends Book{ }
class BookList extends ArrayList
{
public int count = 0;
public boolean add(Object o)
{
if(o instanceof Book b) return super.add(b);
else return count++ == -1;
}
}
//in valid context
BookList list = new BookList();
list.add(new Book());
list.add(new TextBook());
list.add("hello");
System.out.println(list.count);
What will it print?
You had to select 1 option(s)
0
1
2
It will not compile because the add method does not correctly override the add method from ArrayList.
It will not compile because on incorrect usage of instanceof.
It will throw an exception at runtime.
None
Q41. What will be the result of attempting to compile and run the following class?
public class TestClass{
public static void main(String args[ ] ){
int i, j, k;
i = j = k = 9;
System.out.println(i);
}
}
You had to select 2 option(s)
The code will not compile because unlike in c++, operator '=' cannot be chained i.e. a = b = c = d is invalid.
The code will not compile as 'j' is being used before getting initialized.
The code will compile correctly and will display '9' when run.
The code will not compile as 'j' and 'i' are being used before getting initialized.
All the variables will get a value of 9.
Q42. Given:
Connection con = DriverManager.getConnection(dbURL);
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?
You had to select 1 option(s)
stmt.commit();
con.commit();
stmt.commit(true);
No code is necessary.
None
Q43. Identify correct statements about -classpath and --module-path options while executing a java program.
You had to select 3 option(s)
A modular jar placed on the classpath results in a named application module.
A non-modular jar placed on the classpath results in an automatic module.
A non-modular jar placed on the module-path results in an automatic module.
A modular jar placed on the module-path results in a named application module.
If a package is available in a jar on the classpath as well as in another jar on the module-path, the one on the classpath is ignored.
Classpath or module-path are mutually exclusive i.e. only one of them should be used.
Q44. Which statements about the following code contained in BankAccount.java are correct?
interface Account{
public default String getId(){
return "0000";
}
}
interface PremiumAccount extends Account{
public String getId();
}
public class BankAccount implements PremiumAccount{
public static void main(String[] args) {
Account acct = new BankAccount();
System.out.println(acct.getId());
}
}
You had to select 1 option(s)
It will print 0000 when run.
It will compile if class BankAccount provides an implementation for getId method.
It will not compile unless interface PremiumAccount is marked abstract.
It will compile if getId method in PremiumAccount is replaced with:
public String getId(){ super.getId(); }
It will compile if getId method in PremiumAccount is replaced with:
public default String getId(){ super.getId(); }
It will compile if getId method in PremiumAccount is replaced with:
public default String getId(){ super(); }
None
Q45. Which of the following interface definitions can use Lambda expressions?
You had to select 1 option(s)
interface A{
}
@FunctionalInterface
interface A{
default void m(){};
}
interface A{
void m(){};
}
interface A{
default void m1(){};
void m2();
}
@FunctionalInterface
interface A{
void m1();
void m2();
}
None
Q46. Given:
class Booby{
}
class Dooby extends Booby{
}
class Tooby extends Dooby{
}
public class TestClass {
Booby b = new Booby();
Tooby t = new Tooby();
public void do1(List dataList){
//1 INSERT CODE HERE
}
public void do2(List dataList){
//2 INSERT CODE HERE
}
}
and the following four statements:
1. b = dataList.get(0);
2. t = dataList.get(0);
3. dataList.add(b);
4. dataList.add(t);
What can be inserted in the above code?
You had to select 1 option(s)
Statements 1 and 3 can inserted at //1 and Statements 2 and 4 can be inserted at //2.
Statement 4 can inserted at //1 and Statement 1 can be inserted at //2.
Statements 3 and 4 can inserted at //1 and Statements 1 and 2 can be inserted at //2.
Statements 1 and 2 can inserted at //1 and Statements 3 and 4 can be inserted at //2.
Statement 1 can inserted at //1 and Statement 4 can be inserted at //2.
None
Q47. What will the following line of code print?
System.out.println(LocalDate.of(2022, Month.JANUARY, 01)
.format(DateTimeFormatter.ISO_DATE_TIME));
You had to select 1 option(s)
01 Jan 2022
01 January 2022 00:00:00
2022-01-01
2022-01-01T00:00:00
Exception at run time.
None
Q48. What will the following program print?
public class TestClass{
static boolean b;
static int[] ia = new int[1];
static char ch;
static boolean[] ba = new boolean[1];
public static void main(String args[]) throws Exception{
var x = false;
if( b ){
x = ( ch == ia[ch]);
}
else x = ( ba[ch] = b );
System.out.println(x+" "+ba[ch]);
}
}
You had to select 1 option(s)
true true
true false
false true
false false
It will not compile.
None
Q49. What, if anything, is wrong with the following code?
void test(int x){
switch(x){
case 1:
case 2:
case 0:
default :
case 4:
case 'a'|'b': System.out.println('c');
}
}
You had to select 1 option(s)
Data Type of 'x' is not valid to be used as an expression for the switch clause.
The case label 0 must precede case label 1.
Each case section must end with a break keyword.
The default label must be the last label in the switch statement.
There is nothing wrong with the code.
The last case statement is invalid.
None
Q50. 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));
}
}
You had to select 1 option(s)
3000
3000.0
compilation error at //3
compilation error at //4
compilation error at //5
Exception at run time.
None
Q51. Assuming that the following method will always be called with a phone number in the format ddd-ddd-dddd (where d stands for a digit), what can be inserted at //1 so that it will return a String containing "xxx-xxx-"+dddd, where dddd represents the same four digits in the original number?
public static String hidePhone(String fullPhoneNumber){
//1 Insert code here
}
You had to select 2 option(s)
String mask = "xxx-xxx-";
mask.append(fullPhoneNumber.substring(8));
return mask;
return new StringBuilder("xxx-xxx-")+fullPhoneNumber.substring(8);
return new StringBuilder(fullPhoneNumber).replace(0, 7, "xxx-xxx-").toString();
return "xxx-xxx-"+fullPhoneNumber.substring(8, 12);
Q52. Given:
var al = new ArrayList();
al.forEach( k -> {
System.out.print(k.length());
});
Identify correct statements.
You had to select 1 option(s)
The type of k is Object.
The type of al is List.
The code will not compile.
The code will compile but will throw an exception at run time.
The code will compile and run without any exception.
None
Q53. Given:
//in file Movable.java
package p1;
public interface Movable {
int location = 0;
void move(int by);
public void moveBack(int by);
}
//in file Donkey.java
package p2;
import p1.Movable;
public class Donkey implements Movable{
int location = 200;
public void move(int by) {
location = location+by;
}
public void moveBack(int by) {
location = location-by;
}
}
//in file TestClass.java
package px;
import p1.Movable;
import p2.Donkey;
public class TestClass {
public static void main(String[] args) {
Movable m = new Donkey();
m.move(10);
m.moveBack(20);
System.out.println(m.location);
}
}
Identify the correct statement(s).
You had to select 1 option(s)
Donkey.java will not compile.
TestClass.java will not compile.
Movable.java will not compile.
It will print 190 when TestClass is run.
It will print 0 when TestClass is run.
None
Q54. Identify correct statements about the modular JDK.
You had to select 3 option(s)
The base module does not depend on any module while every other module depends on the base module.
The set of modules of the modular JDK can be combined to create configurations corresponding to the full Java SE Platform, the full JRE, and the full JDK.
The standard modules of the modular JDK are governed by the Java Community Process while non-standard ones are not.
A standard module may contain a standard or non-standard API package but must not export any non-standard package.
Q55. Which of these statements concerning maps are true?
You had to select 1 option(s)
It is permissible for a map to contain itself as a key.
values() method returns an instance of Set.
The Map interface extends the Collection interface.
All keys in a map are unique.
All Map implementations keep the keys sorted.
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