Skip to content
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Java Standard Test 9 – 2025
Welcome to your Standard Test 9 - 2025
Name
Email
Phone
Q1. Which of the following code fragments will print 21?
Select 2 option(s):
public class AccessTest {
static int number;
int result = 10;
public static void main(String[] args) {
AccessTest at = new AccessTest();
at.number = 10;
System.out.println(at.addSalt(11));
}
int addSalt(int salt){
return number+salt;
}
}
public class AccessTest {
static int number;
int result = 10;
public static void main(String[] args) {
AccessTest at = new AccessTest();
var result = 11;
number = result;
System.out.println(at.addSalt(this.result));
}
int addSalt(int salt){
return number+salt;
}
}
public class AccessTest {
static int number;
int result = 10;
public static void main(String[] args) {
AccessTest at = new AccessTest();
var result = 10;
number = result;
System.out.println(at.addSalt(11));
}
int addSalt(int salt){
return number+salt;
}
}
public class AccessTest {
static int number;
int result = 10;
public static void main(String[] args) {
AccessTest at = new AccessTest();
number = 11;
var number = at.addSalt(number);
System.out.println(number);
}
int addSalt(int salt){
return number+result;
}
}
public class AccessTest {
static int number;
int result = 10;
public static void main(String[] args) {
AccessTest at = new AccessTest();
number = 11;
number = at.addSalt(at.result);
}
int addSalt(int salt){
var salt = 10;
return number+salt;
}
}
Q2. You are creating a abc.payroll module that makes its two classes - com.abc.payroll.Hourly and com.abc.payroll.Yearly - available to all other modules for use.
Which of the following files correctly defines this module?
Select 1 option(s):
module abc.payroll{
exports com.abc.payroll.*;
}
module abc.payroll{
exports com.abc.payroll;
}
module abc.payroll{
exports com.abc.payroll to all;
}
module abc.payroll{
exports com.abc.payroll.Hourly, com.abc.payroll.Yearly;
}
module abc.payroll{
exports com.abc.payroll.Hourly;
exports com.abc.payroll.Yearly;
}
None
Q3. What will be the result when you try to compile and run the following code?
public class TestClass
{
public static void main(String args[] )
{
var out = new Outer();
System.out.println(out.getInner().getOi());
}
}
class Outer
{
private int oi = 20;
class Inner
{
int getOi() { return oi; }
}
Inner getInner() { return new Inner() ; }
}
Select 1 option(s):
The code will fail to compile as the class Inner is not defined properly.
The code will fail to compile because the reference of an inner class cannot be passed outside the outer class.
The code will fail to compile because the method getOi( ) is not visible from the main( ) method in TestClass.
The code will compile without error and will print 20 when run.
None of the above.
None
Q4. What will be the output of the following class.
class Test{
public static void main(String[] args){
int j = 1;
try{
int i = doIt() / (j = 2);
} catch (Exception e){
System.out.println(" j = " + j);
}
}
public static int doIt() throws Exception { throw new Exception("FORGET IT"); }
}
Select 1 option(s):
It will print j = 1;
It will print j = 2;
The value of j cannot be determined.
It will not compile.
None of the above.
None
Q5. Consider the following interface definition:
interface Measurement{
public default int getLength(){
System.out.println("getting length");
return 10;
};
public default int getBreadth(){
System.out.println("getting breadth");
return 20;
};
}
Several similar default methods need to be added to this interface and each method is supposed to log a message at the start of the method. As of now, the logging is done using just a println statement but it may change later.
What changes can be done in the above interface to make it more maintainable without exposing any non-business functionality to the users of this interface?
Select 1 option(s):
Add a public void log(String msg) method to write the log message and invoke it from other methods instead of using println statement.
Add a protected void log(String msg) method to write the log message and invoke it from other methods instead of using println statement.
Add a private void log(String msg) method to write the log message and invoke it from other methods instead of using println statement.
Add a static void log(String msg) method to write the log message and invoke it from other methods instead of using println statement.
None
Q6. Consider the following classes:
class Boo {
public Boo(){ System.out.println("In Boo"); }
}
class BooBoo extends Boo {
public BooBoo(){ System.out.println("In BooBoo"); }
}
class Moo extends BooBoo implements Serializable {
int moo = 10; { System.out.println("moo set to 10"); }
public Moo(){ System.out.println("In Moo"); }
}
First, the following code was executed and the file moo1.ser was created successfully:
Moo moo = new Moo();
moo.moo = 20;
FileOutputStream fos = new FileOutputStream("c:\\temp\\moo1.ser");
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(moo);
os.close();
Next, the following code was executed.
FileInputStream fis = new FileInputStream("c:\\temp\\moo1.ser");
ObjectInputStream is = new ObjectInputStream(fis);
Moo moo = (Moo) is.readObject();
is.close();
System.out.println(moo.moo);
Which of the following will be a part of the output of the second piece of code?
Select 3 option(s):
In Boo
In BooBoo
In Moo
10
20
moo set to 10
Q7. What can be inserted in the code below so that it will print true when run?
public class TestClass{
public static boolean checkList(List list, Predicate p){
return p.test(list);
}
public static void main(String[] args) {
boolean b = //WRITE CODE HERE
System.out.println(b);
}
}
Select 2 option(s):
checkList(new ArrayList(), al -> al.isEmpty());
checkList(new ArrayList(), ArrayList al -> al.isEmpty());
checkList(new ArrayList(), al -> return al.size() == 0);
checkList(new ArrayList(), al -> al.add("hello"));
checkList(new ArrayList(), (ArrayList al) -> al.isEmpty());
Q8. 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
Q9. Given:
class Automobile{
final String getVin(){ return "1234"; }
}
Identify correct statement(s).
Select 1 option(s):
The following code will not compile because it is missing a zero args constructor:
public final class Car extends Automobile{
}
The following code will not compile because Automobile is final:
class Car{
Automobile a;
}
The following code will not compile because a final class cannot extend any other class:
public final class Car extends Automobile{
}
The following code will compile fine:
final class Car extends Automobile{
}
None
Q10. Given:
//INSERT CODE HERE
subjects.forEach(System.out::print);
Which of the following options when inserted in the above code will print MathChemistryPhysicsEnglish?
Select 1 option(s):
SequencedCollection< String > subjects = new TreeSet< >();
subjects.addFirst("English");
subjects.addFirst("Physics");
subjects.addFirst("Chemistry");
subjects.addFirst("Math");
SequencedCollection< String > subjects = new LinkedHashSet< >();
subjects.addFirst("English");
subjects.addFirst("Physics");
subjects.addFirst("Chemistry");
subjects.addFirst("Maths");
subjects.addFirst("English");
SequencedCollection< String > subjects = new LinkedHashSet<>();
subjects.add("Maths");
subjects.add("Chemistry");
subjects.add("Physics");
subjects.add("English");
subjects.add("Maths");
SequencedCollection< String > subjects = new HashSet();
subjects.add("Maths");
subjects.add("Chemistry");
subjects.add("Physics");
subjects.add("English");
None
Q11. 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
Q12. 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
Q13. NOTE: Although Class.isArray() and Object.clone() methods are not officially on the exam, you may still see a question or two in the exam that requires you to know about these methods.
Given the following declaration:
int[][] twoD = { { 1, 2, 3} , { 4, 5, 6, 7}, { 8, 9, 10 } };
What will the following lines of code print?
System.out.print(twoD[1].length);
System.out.print(twoD[2].getClass().isArray());
System.out.print(twoD[1][2]);
System.out.print(twoD[0] == twoD.clone()[0]);
Select 1 option(s):
4true6true
3true3false
3false3true
4false6true
4true6false
4false6false
None
Q14. For what command line arguments will the following program print true?
class TestClass{
public static void main(String[] args){
Integer i = Integer.parseInt(args[0]);
Integer j = i;
i--;
i++;
System.out.println((i==j));
}
}
Select 3 option(s):
0
-1
127
-256
256
1_00
For all the values between 0 and 255 (both included).
Q15.Given:
In file A.java:
package p1;
import java.util.*;
public class A {
public String name = "A";
protected A(){ }
}
In file B.java:
package p2;
import p1.*;
public class B extends A{
public String name = "B";
public B(){ super(); }
}
In file TestClass.java:
import p1.*;
import p2.*;
public class TestClass
{
public static void main(String[] args) {
A a = new B();
System.out.println(a.name);
}
}
What will be the result of compiling and executing Testclass?
Select 1 option(s):
Compilation failure for class B
A
B
Compilation failure for class TestClass
None
Q16. What will the following code print when run?
import java.util.function.Predicate;
class Employee{
int age; //1
}
public class TestClass{
public static boolean validateEmployee(Employee e, Predicate p){
return p.test(e);
}
public static void main(String[] args) {
Employee e = new Employee(); //2
System.out.println(validateEmployee(e, e->e.age<10000)); //3
}
}
Select 1 option(s):
It will fail to compile at line marked //1
It will fail to compile at line marked //2
It will fail to compile at line marked //3
It will compile fine and print true when run.
It will compile fine and print false when run.
None
Q17. Given:
interface I { }
class A implements I{
public String toString(){ return "in a"; }
}
class B extends A{
public String toString(){ return "in b"; }
}
public class TestClass {
public static void main(String[] args) {
B b = new B();
A a = b;
I i = a;
System.out.println(i);
System.out.println((B)a);
System.out.println(b);
}
}
What will be printed when the above code is compiled and run?
Select 1 option(s):
in i
in a
in b
I
A
in b
in a
in a
in b
in a
in b
in b
in b
in b
in b
None
Q18. Given:
class A extends Thread
{
public void run()
{
System.out.println("Starting loop");
try{
Thread.sleep(10000); //1 sleep for 10 secs
}catch(Exception e){ e.printStackTrace(); }
System.out.println("Ending loop");
}
}
public class TestClass
{
public static void main(String args[]) throws Exception
{
A a = new A();
a.start();
Thread.sleep(100);
a.interrupt();
}
}
What are the states of the main thread and the "A" thread created in the above program just before the main thread calls a.interrupt() and after the A thread has called Thread.sleep(10000)?
Select 1 option(s):
main thread: RUNNABLE
A thread: RUNNABLE
main thread: NEW
A thread: WAITING
main thread: BLOCKED
A thread: RUNNABLE
main thread: RUNNABLE
A thread: TIMED_WAITING
main thread: RUNNABLE
A thread: WAITING
None
Q19. Given:
var nums = IntStream.range(1, 5);
Which of the following options will compute the average of the numbers in the nums stream?
Select 3 option(s):
double average = nums.collect(Collectors.averagingInt(i->i));
double average = nums.mapToObj(i->i).collect(Collectors.averagingInt(i->i));
double average = nums.average().getAsDouble();
double average = nums.parallelStream().mapToInt(i->i).average();
double average = nums.parallel().mapToDouble(i->i).average().getAsDouble();
Q20. Consider the following code:
public class FileCopier {
public static void copy(String records1, String records2) {
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 (FileNotFoundException | IndexOutOfBoundsException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
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 it does not handle exceptions correctly.
The program will compile but will throw an exception at run time.
The program will not compile because the catch clause is used incorrectly.
It will compile and run without any error or exception.
None
Q21. What will the following code print when compiled and run?
int[][] ab = { {1, 2, 3}, {4, 5} };
for(var i=0; i<ab.length; i++){
for(var j=0; j<ab[i].length; j++){
System.out.print(ab[i][j]+" ");
if(ab[i][j] == 2){
break;
}
}
continue;
}
Select 1 option(s):
1 2 3 4 5
1 2
1 3 4 5
1 2 4 5
2 3 5
It will not compile.
None
Q22. 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
Q23. Which of the following statements can be inserted at // 1 to make the code compile without errors?
public class InitTest{
static int si = 10;
int i;
final boolean bool;
// 1
}
Select 1 option(s):
instance { bool = true; }
InitTest() { si += 10; }
{ si = 5; i = bool ? 1000 : 2000;}
{ i = 1000; }
{ bool = (si > 5); i = 1000; }
None
Q24. What will the following code print when run?
public class Noobs {
public void m(int a){
System.out.println("In int ");
}
public void m(char c){
System.out.println("In char ");
}
public static void main(String[] args) {
Noobs n = new Noobs();
int a = 'a';
char c = 6;
n.m(a);
n.m(c);
}
}
Select 1 option(s):
In int
In char
In char
In int
In int
In int
In char
In char
It will not compile.
None
Q25. Which of the following sets of interface definitions are valid?
Select 1 option(s):
interface Measurement{
public int getLength(){
return 0;
}
}
interface Size extends Measurement{
public int getLength();
}
interface Measurement{
public default int getLength(){
return 0;
}
public static int getBreadth(){ return 0; }
}
interface Size extends Measurement{
public static final int UNIT = 100;
public static int getLength(){ return 10;}
}
interface Measurement{
public int getLength();
public static int getBreadth(){ return 0; }
private void helper(){ }
}
interface Size extends Measurement{
private void helper(){ }
}
interface Measurement{
public default final int getUnit(){ return 100; }
private void helper(){ }
}
interface Size extends Measurement{
public int getLength();
}
interface Measurement{
public int getLength();
public static int getBreadth(){ return 0; }
private void helper(){ }
}
interface Size extends Measurement{
private final int STEP = 10;
}
None
Q26. What will the following code print when run?
public class Test {
static String s = "";
public static void m0(int a, int b) {
s += a;
m2();
m1(b);
}
public static void m1(int i) {
s += i;
}
public static void m2() {
throw new NullPointerException("aa");
}
public static void m() {
m0(1, 2);
m1(3);
}
public static void main(String args[]) {
try {
m();
} catch (Exception e) {
}
System.out.println(s);
}
}
Select 1 option(s):
1
12
123
2
It will throw exception at runtime.
None
Q27. Given:
Path p1 = Paths.get("c:\\a\\b\\c.java");
What will p1.getName(2).toString() return?
Select 1 option(s):
a
b
c
c.java
None
Q28. Given :
1. The time zone of America/New York is normally 5 hours behind UTC.
2. Day light saving is ON during June in New York. (This means, clocks in New York are 1 hour ahead of the regular time that would have been shown when day light saving is OFF.)
What will the following code print when compiled and run?
LocalDate ld = LocalDate.now().withMonth(6).withDayOfMonth(2);
LocalTime lt = LocalTime.of(6, 0, 0);
LocalDateTime ldt = ld.atTime(lt);
ZoneOffset nyOffset = ZoneOffset.ofHoursMinutes(-5, 0);
ZoneId nyZone = ZoneId.of("America/New_York");
OffsetDateTime nyOdt = ldt.atOffset(nyOffset);
ZonedDateTime nyZdt = ldt.atZone(nyZone);
Duration d = Duration.between(nyOdt, nyZdt);
System.out.println(d);
Select 1 option(s):
PT1H
PT0S
PT-1H
PT0H
None
Q29. What will be the output of the following code snippet:
Stream ss = Stream.of("a", "b", "c", "d", "e");
Spliterator sit1 = ss.spliterator();
long s0 = sit1.estimateSize();
Spliterator sit2 = sit1.trySplit();
long s1 = sit1.estimateSize();
long s2 = sit2.estimateSize();
System.out.println( s0 - (s1+s2) );
Select 1 option(s):
0
-1
1
The result will be unpredictable.
None
Q30. Consider the following class:
public class PortConnector{
public PortConnector(int port) throws IOException{
...lot of valid code.
}
...other valid code.
}
You want to write another class CleanConnector that extends from PortConnector. Which of the following statements should hold true for CleanConnector class?
Select 1 option(s):
It is not possible to define CleanConnector that does not throw IOException at instantiation.
PortConnector class itself is not valid because you cannot throw any exception from a constructor.
CleanConnector's constructor cannot throw any exception other than IOException.
CleanConnector's constructor cannot throw any exception other than subclass of IOException.
CleanConnector's constructor cannot throw any exception other than superclass of IOException.
None of these.
None
Q31. Given:
public class Counter{
static AtomicInteger ai = new AtomicInteger(0);
public static void increment(){
//1
}
//other valid code
}
This class is supposed to keep an accurate count for the number of times the increment method is called. Several classes share this class and call its increment method. What should be inserted at //1 ?
Select 2 option(s):
ai.increment();
ai.incrementAndGet();
ai.set(ai.get()+1);
ai.addAndGet(1);
ai.add(1);
ai++;
Q32. 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;
Q33. Given the following code:
class TestClass{
public static void main(String args[]){
int time = 100;
java.sql.Timestamp ts = new java.sql.Timestamp(time);
java.util.Date d = new java.util.Date();
ts = new java.sql.Timestamp(d.getTime());
System.out.println(ts);
}
}
and the following commands:
javac TestClass.java
jdeps -summary TestClass.class
What will be the output?
Select 1 option(s):
TestClass.class -> java.base
TestClass.class -> java.sql
TestClass.class -> java.util
TestClass.class -> java.base
TestClass.class -> java.base
TestClass.class -> java.sql
TestClass.class -> java.sql
TestClass.class -> java.util
Compilation will be successful but the jdeps command will generate an error.
None
Q34. What will the following code print when compiled and run?
public class Test{
static int a = 0;
int b = 5;
public void foo(){
while(b>0){
b--;
a++;
}
}
public static void main(String[] args) {
var p1 = new Test();
p1.foo();
var p2 = new Test();
p2.foo();
System.out.println(p1.a+" "+p2.a);
}
}
Select 1 option(s):
0 10
10 10
10 0
5 5
0 5
5 0
None
Q35. Given:
public class TableTest {
static String[][] table;
public static void main(String[] args) {
String[] x = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
String[] y1 = { "1", "2", "3", "4", "5" };
String[] y2 = { "a", "b", "c" };
table = new String[3][];
table[0] = x;
table[1] = y1;
table[2] = y2;
//INSERT CODE HERE
}
}
What can be inserted in the above code to make it print Sun5c?
Select 1 option(s):
for(String[] row : table){
System.out.print(row[row.length]);
}
int i = 0;
for(String[] col : table){
i++;
if(i==col.length){
System.out.print(table[col.length][i]);
}
}
for(var row : table){
System.out.print(row[row.length-1]);
}
for(int i=0; i<table.length-1; i++){
int j = table[i].length-1;
System.out.print(table[i][j]);
}
None
Q36. What will the following code print when compiled and run?
public class TestClass{
public static void main(String[] args) {
int value = 0;
Supplier valueS = ()->value++; //1
value++;//2
System.out.println(value+" "+valueS.get()); //3
}
}
Select 1 option(s):
1 1
2 1
2 2
Compilation error at //1
Compilation error at //2
None
Q37. Consider the following class :
public class Test{
public static void main(String[] args){
if (args[0].equals("open"))
if (args[1].equals("someone"))
System.out.println("Hello!");
else System.out.println("Go away "+ args[1]);
}
}
Which of the following statements are true if the above program is run with the command line :
java Test closed
Select 1 option(s):
It will throw ArrayIndexOutOfBoundsException at runtime.
It will end without exceptions and will print nothing.
It will print Go away
It will print Go away and then will throw ArrayIndexOutOfBoundsException.
None of the above.
None
Q38. Which lines contain a valid constructor in the following code?
public class TestClass{
public TestClass(int a, int b) { } // 1
public void TestClass(int a) { } // 2
public TestClass(String s); // 3
private TestClass(String s, int a) { } //4
public TestClass(String s1, String s2) { }; //5
}
Select 3 option(s):
Line // 1
Line // 2
Line // 3
Line // 4
Line // 5
Q39. What will the following code print when compiled and run?
Select 1 option(s):
null 0
null 1
0
1
0
1
( There is a space before 0 and 1 )
null
null
It will throw a RuntimeException at run time.
None
Q40. What will be the output of the following code:
Stream ss = Stream.of("a", "b", "a", "b", "c", "b");
Map data = ss.collect( Collectors.groupingBy(Function.identity(),
Collectors.counting()));
System.out.println( data );
Select 1 option(s):
{a=2, b=3, c=1}
[6]
{a=1, b=1, c=1}
Compilation failure.
None
Q41. Given the following pairs of method declarations, which of the statements are true?
1.
void perform_work(int time){ }
int perform_work(int time, int speed){ return time*speed ;}
2.
void perform_work(int time){ }
int perform_work(int speed){return speed ;}
3.
void perform_work(int time){ }
void Perform_work(int time){ }
Select 2 option(s):
The first pair of methods will compile without errors and they correctly demonstrate method overloading.
The second pair of methods will compile correctly and overload the method 'perform_work'.
The third pair of methods will compile correctly and overload the method 'perform_work'.
The second pair of methods will not compile correctly.
The third pair of methods will not compile correctly.
Q42. Given:
public class Bandwidth{
public int available = 0;
public int getAvailable(){
return available;
}
public Bandwidth(int quota){
this.available = quota;
}
public void addMore(int more){
available += more;
}
}
and a piece of code from another class:
Bandwidth bw = new Bandwidth(100);
//INSERT CODE HERE
System.out.println(bw.getAvailable());
What can be inserted in the code above so that it will print 0?
Select 2 option(s):
bw(0);
bw.available = 0;
bw.setAvailable(0);
bw = new Bandwidth();
bw.addMore(-bw.getAvailable());
--bw.available;
Q43. Given that SomeException is a checked exception, consider the following code:
//in file A.java
public class A{
protected void m() throws SomeException{}
}
//in file B.java
public class B extends A{
public void m(){ }
}
//in file TestClass.java
public class TestClass{
public static void main(String[] args){
//insert code here. //1
}
}
Which of the following options can be inserted at //1 without resulting in any compilation or runtime errors?
Select 1 option(s):
B b = new A();
b.m();
A a = new B();
a.m();
A a = new B();
( ( B) a ).m();
Object o = new B();
o.m();
None of these.
None
Q44. Assuming that Book has appropriate constructor and accessor methods, what will the following code print?
List books = Arrays.asList(
new Book("Freedom at Midnight", 5.0),
new Book("Gone with the wind", 5.0),
new Book("Midnight Cowboy", 15.0)
);
books.stream()
.filter(b->b.getTitle().startsWith("F"))
.forEach(b->b.setPrice(10.0));
books.stream()
.forEach(b->System.out.println(b.getTitle()+":"+b.getPrice()));
Select 1 option(s):
Freedom at Midnight:5.0
Gone with the wind:5.0
Midnight Cowboy:15.0
Freedom at Midnight:5.0
Gone with the wind:10.0
Midnight Cowboy:10.0
Freedom at Midnight:10.0
Gone with the wind:5.0
Midnight Cowboy:15.0
Freedom at Midnight:10.0
Exception at run time
None
Q45. Consider the following two classes (in the same package but defined in different source files):
public class Square {
double side = 0;
double area;
public Square(double length){ this.side = length; }
public double getSide() { return side; }
public void setSide(double side) { this.side = side; }
double getArea() { return area; }
}
public class TestClass {
public static void main(String[] args) throws Exception {
Square sq = new Square(10.0);
sq.area = sq.getSide()*sq.getSide();
System.out.println(sq.getArea());
}
}
You are assigned the task of refactoring the Square class to make it better in terms of encapsulation. What changes will you make to this class?
Select 4 option(s):
Add a calculateArea method:
private void calculateArea(){
this.area = this.side*this.side;
}
Make side and area fields private.
Change setSide method to:
public void setSide(double d){
this.side = d;
calculateArea();
}
Make the getArea method public.
Add a setArea() method:
public void setArea(double d){ area = d; }
Q46. Which of the following commands can be used to identify class and module dependencies of a class named test.A of module named moduleA without executing it?
Assume that all module files are stored in out directory.
Note: Although identifying module dependency is not explicitly mentioned in the exam objectives, we have seen questions on the exam that require you to know about the tool that is used to identify module dependencies.
Select 1 option(s):
javac --module-path out --list-dependencies moduleA/test.A
jmod --module-path out --describe test.A
javap --module-path out --show-module-resolution test.A
jdeps --module-path out out\moduleA\test\A.class
jdeps --module-path out moduleA\test.A
None
Q47. What will the following code print when compiled and run?
public class ATest {
String global = "111";
public int parse(String arg){
int value = 0;
try{
String global = arg;
value = Integer.parseInt(global);
}
catch(Exception e){
System.out.println(e.getClass());
}
System.out.print(global+" "+value+" ");
return value;
}
public static void main(String[] args) {
ATest ct = new ATest();
System.out.print(ct.parse("333"));
}
}
Select 1 option(s):
111 333 333
333 333 333
111 333
java.lang.Exception
java.lang.NumberFormatException
Compilation fails.
None
Q48. Consider the following code:
import java.io.*;
public class TestClass {
public static void main(String[] args) throws Exception {
var f = new File("x"); //1
var bfr1 = new BufferedReader(new FileReader(f)); //2
var bfr2 = new BufferedReader( bfr1 ); //3
var pw = new PrintWriter(new FileReader(f)); //4
}
}
Select the correct statements about the above program.
Select 1 option(s):
// 1 will throw an exception at runtime if a file named "x" does not exist.
//2 and //3 will compile without any error.
//4 will compile without any error.
The complete program will compile without any error.
None of these.
None
Q49. Consider the following code:
public static void findFiles() throws Exception{
Path dir = Paths.get("c:\\temp");
//INSERT CODE HERE
for(Path p : ds){
System.out.println(p);
}
}
catch(Exception e){
e.printStackTrace();
}
}
What should be inserted in the above code so that it will print all the files with extension gif and jpeg?
Select 1 option(s):
try{ DirectoryStream< Path > ds = Files.newDirectoryStream(dir, "*.[gif,jpeg]");
try{ DirectoryStream< Path > ds = Files.newDirectoryStream(dir, "*.{gif,jpeg}");
try{ DirectoryStream< Path > ds = Files.newDirectoryStream(dir, "*.gif,*.jpeg");
try{ DirectoryStream< Path > ds = Files.newDirectoryStream(dir, "gif,jpeg");
None
Q50. What will the following code print?
enum AccountType{
CHECKING, SAVINGS, FD;
public String toString(){ return this.name().toLowerCase(); }
public static String getAccountType(String type){
try{
AccountType at = AccountType.valueOf(type);
return (at.ordinal()%2 == 0) ? at.name().toLowerCase():at.name().toUpperCase();
}catch(Exception e){
return "NOT_SUPPORTED";
}
}
public static void main(String[] args) {
for(int i=0; i<AccountType.values().length; i++){
String name = AccountType.values()[i].toString();
System.out.print(AccountType.getAccountType(name));
}
}
}
Select 1 option(s):
NOT_SUPPORTEDNOT_SUPPORTEDNOT_SUPPORTED
CHECKINGSAVINGSFD
checkingSAVINGSfd
CHECKINGsavingsFD
not_supportednot_supportednot_supported
NOT_SUPPORTEDnot_supportedNOT_SUPPORTED
None
Time's 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