0% found this document useful (0 votes)
5 views

STEP Java Assessment

The document details a STEP Java Assessment taken by Nahak Krishnaprasad Daktar, covering various Java concepts such as the static keyword, object-oriented programming, and the final keyword. The assessment includes multiple-choice questions with feedback on the correct answers and points scored. The total score for the assessment is 24 out of 55.

Uploaded by

krishna.nahak025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

STEP Java Assessment

The document details a STEP Java Assessment taken by Nahak Krishnaprasad Daktar, covering various Java concepts such as the static keyword, object-oriented programming, and the final keyword. The assessment includes multiple-choice questions with feedback on the correct answers and points scored. The total score for the assessment is 24 out of 55.

Uploaded by

krishna.nahak025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

3/31/25, 1:46 PM STEP Java Assessment

STEP Java Assessment Total points 24/55

Instructions:

1, Read the instructions carefully for each question and answer the question accordingly.
2, It is not necessary that every question will have multiple answers.

Email *

[email protected]

0 of 0 points

Name *

Nahak Krishnaprasad Daktar

Java Basics - static keyword 7 of 9 points

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsco… 1/44
3/31/25, 1:46 PM STEP Java Assessment

Q.1 What will be output of above Code? 2/2

class Student {
int rollno;
String name;

void value() {
rollno = 101;
System.out.println("value method rollno =" + rollno);
}

static void display() {


static int a = 12;
System.out.println(" a =" + a);
}

public class Main {


public
static void main(String ar[]) { Student.display(); }
}

Exception will come at run time

a = 12

No output will come

Compile time Error will come

Feedback

Option C is correct

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsco… 2/44
3/31/25, 1:46 PM STEP Java Assessment

Q.2 Which of the following statements is true about static methods and 1/1
variables in Java?

A static method can directly access instance variables.

A static method can be overridden by a non-static method.

Static variables are shared among all instances of a class.

A static method can access the this keyword.

Feedback

Option C is correct

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsco… 3/44
3/31/25, 1:46 PM STEP Java Assessment

Q.3 What will be output of given Code? 2/2

class Example {
static int x = 10;
static {
x += 5;
System.out.println("Static Block: x = " + x);
}
Example() {
x += 10;
System.out.println("Constructor: x = " + x);
}
}

public class Main {


public
static void main(String[] args) {
Example ex1 = new Example();
Example ex2 = new Example();
}
}

Static Block: x = 15, Constructor: x = 25, Constructor: x = 35

Static Block: x = 15, Constructor: x = 20, Constructor: x = 30

Static Block: x = 10, Constructor: x = 20, Constructor: x = 30

Static Block: x = 15, Constructor: x = 30, Constructor: x = 40

Feedback

Option A is correct

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsco… 4/44
3/31/25, 1:46 PM STEP Java Assessment

Q.4 What will be output of given Code? 0/2

class Student {
int rollno;
String name;

void value() {
myfun(); // Line-5
System.out.println("it is showing an error");
}

void myfun() { System.out.println("code throwing exception"); }

static void display() {


System.out.println(“new begining");
value(); // Line-15
}

class Main {
public
static void main(String ar[]) {
Student s1 = new Student();

s1.display(); // Line-23
}
}

Compile time error at Line-23

Compile time error at Line-15

Compile time error at Line-5

new beginning, code throwing exception, it is showing an error

Correct answer

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsco… 5/44
3/31/25, 1:46 PM STEP Java Assessment

Compile time error at Line-15

Q.5 Which of the following statements is false regarding static variables 1/1
in Java?

Static variables are initialized before any instance of the class is created.

Static variables are initialized before any static method is invoked.

Static variables can only be initialized within a static block.

Static variables are initialized only once, when the class is loaded.

Feedback

Option C is correct

Q.6 Which of the following is true regarding static and non-static context 1/1
in Java?

A non-static method can call a static method directly.

A static method can call a non-static method directly.

A static method can access non-static variables directly.

A non-static method cannot access static variables.

Feedback

Option A is correct

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsco… 6/44
3/31/25, 1:46 PM STEP Java Assessment

Java Basics - Object Oriented Programming 4 of 8 points

Q.1 What will be output of given Code? 1/1

class A {
Void showMethod(int a) { System.out.println(“int a…..”); }

Void showMethod(Integer a) { System.out.println(“Integer a…..”); }

Void showMethod(Object a) { System.out.println(“Object a…..”); }

} class Main {
public
static void main(String ar[]) {
A a = new A();

a.showMethod(23);
}
}

Integer a…..

Object a…..

int a…..

Ambiguity error will come

Feedback

Option C is Correct

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsco… 7/44
3/31/25, 1:46 PM STEP Java Assessment

Q.2 What will be output of given Code? 1/1

class Student {
float value(int a, int b) { return (float)(a + b); }

int value(int a, int b) { return a + b; }

class Main {
public
static void main(String ar[]) {
Student s1 = new Student();

System.out.println(s1.value(2, 4));
System.out.println(s1.value(3, 3));
}
}

6.0 , 6

6 , 6.0

No output will generate

Ambiguity error will come

Feedback

Option D is correct

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsco… 8/44
3/31/25, 1:46 PM STEP Java Assessment

Q.3 What will be output of given Code? 0/2

class A {
public
boolean show(int a, int b) {
System.out.println(“show method”);
return !(a > b ? ((a + b) > b) || ((b + a) < a)
: ((a - b) <= b) && ((b * a) > a));
}
} class B extends A {
protected
boolean show(int a, int b) {
System.out.println(“show method”);
return !(a < b ? ((a * b) > b) || ((b - a) > a)
: ((a * b) >= b) && ((a * a) > b));
}
}

public class Main {


public
static void main(String[] args) {
A obj = new B();
System.out.println(obj.show(11, 9));
}
}

The code will give compile time error

The code will compile successfully and output will be false

The code will compile, but throw a runtime exception.

The code will compile successfully and output will be true

Correct answer

The code will give compile time error

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsco… 9/44
3/31/25, 1:46 PM STEP Java Assessment

Q.4 What will be output of given Code? 0/2

class A {
protected
boolean show(int a, int b) {
System.out.println(“show method”);
return !(a > b ? ((a + b) > b) || ((b + a) < a)
: ((a - b) <= b) && ((b * a) > a));
}
} class B extends A {
public
boolean show(int a, int b) {
System.out.println(“show method”);
return !(a < b ? ((a * b) > b) || ((b - a) > a)
: ((a * b) >= b) && ((a * a) > b));
}
}

public class Main {


public
static void main(String[] args) {
A obj = new B();
System.out.println(obj.show(9, 7));
}
}

The code will compile successfully and output will be true

The code will compile successfully and output will be false

The code will give compile time error

The code will compile, but throw a runtime exception.

Correct answer

The code will compile successfully and output will be false

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 10/44
3/31/25, 1:46 PM STEP Java Assessment

Q.5 What will be output of given Code? 2/2

class A {
int x;
String uname;
A(int a, String b) {
x = a;
uname = b;
System.out.println(
"A constructor x = " + x +” and uname = ”+ uname);
}
}

class B extends A {
int x;
String uname;
B(int a, String b) {
x = a;
uname = b;
System.out.println(
"B constructor x = " + x +” and uname = ”+ uname);
}
} public class Main2 {
public
static void main(String ar[]) { A obj = new B(101, "john"); }
}

A constructor x = 101 and uname = john, B constructor x = 101 and uname = john

A constructor x = 0 and uname = null, B constructor x = 101 and uname = john

Compilation error

A constructor x = 101 and uname = john,B constructor x = 0 and uname = null

Feedback

Option C is correct

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 11/44
3/31/25, 1:46 PM STEP Java Assessment

Java Basics - final keyword, abstract classes and interfaces 6 of 8 points

Q.1 Which of the following is true about a class declared as final? 1/1

It cannot be subclassed.

It cannot have any final methods.

It must contain only final methods.

It can be inherited by other classes.

Other:

Feedback

Option A is Correct

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 12/44
3/31/25, 1:46 PM STEP Java Assessment

Q.2 What will happen if you declare a class as both final and abstract? 1/1

final abstract class Test {

// some code

The code will give compile time error

The code will compile, but throw a runtime exception.

The code will compile and run successfully.

None of the above

Other:

Feedback

Option A is correct

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 13/44
3/31/25, 1:46 PM STEP Java Assessment

Q.3 What will be output of given Code? 0/2

class A {
final int a;
A() {
a = 10;
System.out.println("constructor called");
}
A(int val) { System.out.println("one pera constructor called"); }

A(int val1, int val2) { System.out.println("two pera constructor called"); }

void display() { System.out.println("value a = " + a); }


}
public class Main {
public
static void main(String ar[]) {
A obj = new A();
System.out.println("a = " + obj.a);
A obj2 = new A(2, 3);
System.out.println("a = " + obj2.a);
}
}

constructor called a = 10, two pera constructor called a = 10

The code will compile, but throw a runtime exception.

The code will give compile time error

constructor called a = 10, two pera constructor called a = 0

Correct answer

The code will give compile time error

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 14/44
3/31/25, 1:46 PM STEP Java Assessment

Q.4 What will be output of given Code? 2/2

class Test {
final int x;
void modify() { x = 20; }
void display() { System.out.println(“x = ”+ x); }
}

public class Main {


public
static void main(String[] args) {
Test test = new Test();
test.modify();
test.display(); // Line-5
}
}

The code will compile successfully and output will be x = 20

The code will give compile time error

The code will compile, but throw a runtime exception.

if we comment Line-5 then output will be x = 0

Feedback

Option B is correct

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 15/44
3/31/25, 1:46 PM STEP Java Assessment

Q.5 What happens if you declare a method in an abstract class without the 1/1
abstract keyword and without a method body?

The class will not compile.

The method will be treated as an abstract method.

The method will be treated as a concrete method with a default implementation.

The method will be inherited without a body in subclasses.

Feedback

Option A is correct

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 16/44
3/31/25, 1:46 PM STEP Java Assessment

Q.6 What will be output of given Code? 1/1

interface X {
default void show() { System.out.println("X"); }
}
class Y implements X {
public
void show() { System.out.println("Y"); }
} public class Test {
public
static void main(String[] args) {
X obj = new Y();
obj.show();
}
}

Compilation error

Runtime exception

Feedback

Option B is correct

Exception Handling in Java 3 of 9 points

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 17/44
3/31/25, 1:46 PM STEP Java Assessment

Q.1 What will be output of given Code? 0/2

public
class Test {
public
static void main(String[] args) {
try {
throw new RuntimeException("Runtime");
}
catch (RuntimeException e) {
throw new Exception("Exception");
}
catch (Exception e) {
System.out.println(e.getMessage());
}
finally {
System.out.println("Finally");
}
}
}

Exception\nFinally

Runtime\nFinally

Compilation error

Finally

Correct answer

Compilation error

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 18/44
3/31/25, 1:46 PM STEP Java Assessment

Q.2 What will be output of given Code? 2/2

class A {
int id;
String name;
void show() { System.out.println("show method"); }
}

public class Main {


public
static void main(String ar[]) {
A obj = new A();
try {
System.out.println(“beginning my journey……”);

System.out.println(10 / obj.id);
System.out.println(“handling obstacles”);
} catch (ArithmeticException e) {
obj = null;
obj.show();
} catch (NullPointerException e) {
System.out.println(e.getMessage());
} finally {
System.out.println(“finally block called”);
}
}
}

beginning my journey……\nfinally block called\n NullPointerException in main


Thread

beginning my journey\n ArithmeticException\nNullPointer Exception\n finally block


called

Compilation error

beginning my journey……\n handling obstacles \n finally block called


\nArithmeticException

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 19/44
3/31/25, 1:46 PM STEP Java Assessment

Feedback

Option A is correct

Q.3 What will be output of given Code? 1/1

class Main {
public
static void main(String ar[]) {
try {
System.out.println("statement-1");
int a = 9;
int b = 10;
System.out.println("statement-2 and (a+b)= " + (a + b));
} finally {
System.out.println("finally block called and and (a+b)=" + (a + b));
}
}
}

statement-1\n statement-2 and (a+b)= 19

statement-1\nstatement-2 and (a+b)= 19 \n finally block called and and (a+b)=19

Compilation error

finally block called and and (a+b)=19

Feedback

Option C is correct

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 20/44
3/31/25, 1:46 PM STEP Java Assessment

Q.4 What will be output of given Code? 0/2

class CustomException extends Exception {


public
CustomException(String message) { super(message); }
}

public class TestCustomException {


public
static void main(String[] args) {
try {
System.out.println(method1());
} catch (CustomException e) {
System.out.println("Caught CustomException: " + e.getMessage());
}
}

public
static String method1() throws CustomException {
try {
throw new CustomException("Error in method1");
} catch (CustomException e) {
System.out.println("Caught in method1: " + e.getMessage());
throw e; // Re-throwing the exception
} finally {
return "method1: Finally block executed";
}
}
}

Compilation error

Caught in method1: Error in method1\n method1: Finally block executed

method1: Finally block executed

Caught in method1: Error in method1\n method1: Finally block executed


\nCaught in method1: Error in method1

Correct answer

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 21/44
3/31/25, 1:46 PM STEP Java Assessment

Caught in method1: Error in method1\n method1: Finally block executed

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 22/44
3/31/25, 1:46 PM STEP Java Assessment

Q.5 What will be output of given Code? 0/2

class MyException {
public
static void main(String[] args) {
try {
method1();
} catch (Exception e) {
System.out.println("Caught in main: " + e.getMessage());
}
}

public
static void method1() throws Exception {
try {
method2();
} catch (Exception e) {
System.out.println("Caught in method1: " + e.getMessage());
throw new Exception("Exception from method1");
}
}

public
static void method2() throws Exception {
try {
method3();
} catch (Exception e) {
System.out.println("Caught in method2: " + e.getMessage());
throw new Exception("Exception from method2");
}
}

public
static void method3() throws Exception {
throw new Exception("Exception from method3");
}
}

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 23/44
3/31/25, 1:46 PM STEP Java Assessment

A.) Caught in method3: Exception from method3

Caught in method2: Exception from method2

Caught in method1: Exception from method1

Caught in main: Exception from main

B.) Caught in method3: Exception from method3

Caught in method2: Exception from method2

Caught in method1: Exception from method1

C.) Caught in method2: Exception from method3

Caught in method1: Exception from method2

Caught in main: Exception from method1

D.) Caught in method1: Exception from method1

Caught in main: Exception from method1

Threads in Java 1 of 6 points

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 24/44
3/31/25, 1:46 PM STEP Java Assessment

Q.1 What will be output of given Code? 0/1

class Mythread extends Thread {


public
void run() {
for (int i = 1; i <= 5; i++) {
System.out.println("RUN METHOD");
}
}
} public class Main {
public
static void main(String ar[]) {
Mythread mt = new Mythread();
mt.start();
mt.start();
for (int i = 1; i <= 5; i++) {
System.out.println("Hello world!");
}
}
}

The code compile, but give runtime exception

5 time’s RUN METHOD, 5 time’s Hello world! In any order

Compilation error

5 time’s Hello world!

Correct answer

Compilation error

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 25/44
3/31/25, 1:46 PM STEP Java Assessment

Q.2 What will be output of given Code? 1/1

class Mythread extends Thread {


public
void run() {
for (int i = 1; i <= 5; i++) {
System.out.println("RUN METHOD");
}
}

}
public class Main {
public
static void main(String ar[]) {
Mythread mt = new Mythread();

for (int i = 1; i <= 5; i++) {


System.out.println("Hello world!");
}
mt.run();
}
}

5 time’s Hello world!, 5 time’s RUN METHOD

5 time’s RUN METHOD, 5 time’s Hello world! In any order

Compilation error

The code will compile, but give runtime exception

Feedback

Option A is Correct

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 26/44
3/31/25, 1:46 PM STEP Java Assessment

Q.3 What will be output of given Code? 0/2

class MyThread extends Thread {


public
void run() {
System.out.println("Thread Started");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("Thread Interrupted");
}
System.out.println("Thread Finished");
}
}

public class TestThread {


public
static void main(String[] args) throws InterruptedException {
MyThread t1 = new MyThread();
MyThread t2 = new MyThread();

t1.start();
t1.join(500); // Waits for t1 for 500ms

t2.start();
t1.join(); // Waits for t1 to finish

System.out.println("Main Finished");
}
}

A.) Thread Started

Thread Started

Thread Finished

Main Finished

Thread Finished
https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 27/44
3/31/25, 1:46 PM STEP Java Assessment

B.) Thread Started

Thread Finished

Thread Started

Thread Finished

Main Finished

C.)Thread Started

Main Finished

Thread Finished

Thread Started

Thread Finished

D.)Thread Started

Thread Interrupted

Thread Started

Thread Finished

Main Finished

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 28/44
3/31/25, 1:46 PM STEP Java Assessment

Q.4 What will be output of given Code? 0/2

class MyRunnable implements Runnable {


public
void run() {
for (int i = 0; i < 5; i++) {
System.out.println(Thread.currentThread().getName() + ": " + i);
}
}
}

public class TestRunnable {


public
static void main(String[] args) {
Thread t1 = new Thread(new MyRunnable());
Thread t2 = new Thread(new MyRunnable());

t1.start();
t2.run();
}
}

A.) Thread-0: 0

Thread-0: 1

Thread-0: 2

Thread-0: 3

Thread-0: 4

main: 0

main: 1

main: 2

main: 3

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 29/44
3/31/25, 1:46 PM STEP Java Assessment

main: 4

B.)Thread-0: 0

Thread-0: 1

Thread-0: 2

Thread-0: 3

Thread-0: 4

Thread-1: 0

Thread-1: 1

Thread-1: 2

Thread-1: 3

Thread-1: 4

C.)main: 0

main: 1

main: 2

main: 3

main: 4

Thread-0: 0

Thread-0: 1

Thread-0: 2

Thread-0: 3

Thread-0: 4

D.)main: 0

main: 1

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 30/44
3/31/25, 1:46 PM STEP Java Assessment

main: 2

main: 3

main: 4

Correct answer

Collections in Java 2 of 8 points

Q.1 Which of the following classes allow null values as an element? 0/1

TreeSet

ArrayList

HashSet

Hashtable

Correct answer

ArrayList

HashSet

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 31/44
3/31/25, 1:46 PM STEP Java Assessment

Q.2 What will be output of given Code? 0/2

import java.util.*;

class Student {
int id;
String name;

Student(int id, String name) {


this.id = id;
this.name = name;
}

public
int hashCode() { return this.id; }

public
boolean equals(Object o) { return false; }

public
String toString() { return this.id+" " ; }

public class Main {


public
static void main(String ar[]) {
Student s1 = new Student(101, "ram");
Student s2 = new Student(102, "gita");
Student s3 = new Student(101, "ram");
Student s4 = new Student(103, "abhi");
Student s5 = new Student(104, "ram");
Student s6 = new Student(104, "harish");
Student s7 = new Student(101, "gita");
Student s8 = new Student(103, "sita");
Student s9 = new Student(104, "ravi");

Set sets = new LinkedHashSet();

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 32/44
3/31/25, 1:46 PM STEP Java Assessment

sets.add(s1);
sets.add(s2);
sets.add(s3);
sets.add(s4);
sets.add(s5);
sets.add(s6);
sets.add(s7);
sets.add(s8);
sets.add(s9);
System.out.println(sets);
}
}

[101, 102, 101, 103, 104, 104, 101, 103, 104]

[101, 101, 101, 102, 103, 103, 104, 104, 104]

[101, 102, 103, 104]

[101, 103, 104, 102 ]

Correct answer

[101, 102, 101, 103, 104, 104, 101, 103, 104]

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 33/44
3/31/25, 1:46 PM STEP Java Assessment

Q.3 What will be output of given Code? 1/1

import java.util.*;

public
class Main {
public
static void main(String[] args) {
List<String> list = new LinkedList<>();
list.add("one");
list.add("two");
list.add("three");

Iterator<String> it = list.iterator();
while (it.hasNext()) {
it.next();
it.remove();
}

System.out.println(list.size());
}
}

Compilation error

Feedback

Option A is Correct

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 34/44
3/31/25, 1:46 PM STEP Java Assessment

Q.4 What will be output of given Code? 0/1

import java.util.*;

public
class Main {
public
static void main(String[] args) {
List<String> list = new LinkedList<>();
list.add("one");
list.add("two");
list.add("three");

Iterator<String> it = list.iterator();
while (it.hasNext()) {
it.next();
}
it.remove();
it.remove();
System.out.println(list.size());
}
}

The code compile, but throws Exception at runtime

Compilation error

Correct answer

The code compile, but throws Exception at runtime

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 35/44
3/31/25, 1:46 PM STEP Java Assessment

Q.5 What will be output of given Code? 0/1

import java.util.*;

public
class Main {
public
static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("one");
list.add("two");
list.add("three");

Collections.reverse(list);
list.set(1, "four");

for (String s : list) {


System.out.print(s + " ");
}
}
}

three four one

one four two

three two four

one two three

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 36/44
3/31/25, 1:46 PM STEP Java Assessment

Q.6 What is the time complexity for searching an element in a HashSet? 1/1

O(1)

O(log n)

O(n)

O(n log n)

Feedback

Option A is Correct

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 37/44
3/31/25, 1:46 PM STEP Java Assessment

Q.7 What will be output of given Code? 0/1

import java.util.*;

public
class Main {
public
static void main(String[] args) {
Map<String, String> map = new TreeMap<>();
map.put("c", "three");
map.put("b", "two");
map.put("a", "one");

for (String key : map.keySet()) {


System.out.print(key + " ");
}
}
}

cba

abc

Runtime Exception

one two three

Correct answer

abc

Servlets and JSP 1 of 7 points

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 38/44
3/31/25, 1:46 PM STEP Java Assessment

Q.1 Which method is not part of the HttpServletRequest interface? 0/1

getParameter()

getSession()

getWriter()

getHeader()

Correct answer

getWriter()

Q.2 How can a servlet communicate directly with another servlet? 0/1

By using RequestDispatcher

By using sendRedirect()

By using ServletConfig

By using ServletContext

Correct answer

By using RequestDispatcher

By using sendRedirect()

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 39/44
3/31/25, 1:46 PM STEP Java Assessment

Q.3 In which directory should you place the web.xml file in a Java web 0/1
application?

/src

/META-INF

/WEB-INF

/WEB-INF/classes

Correct answer

/WEB-INF

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 40/44
3/31/25, 1:46 PM STEP Java Assessment

Q.4 What is the behavior of the following servlet code if the doPost() 0/1
method is called with the same session already existing?

public
class MyServlet extends HttpServlet {
protected
void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
HttpSession session = request.getSession(true);
session.setAttribute("user", "John");
PrintWriter out = response.getWriter();
out.println(session.getAttribute("user"));
}
}

It will print "John".

It will throw a NullPointerException.

It will print "null".

It will create a new session every time.

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 41/44
3/31/25, 1:46 PM STEP Java Assessment

Q.5 What will happen if the following code is executed when 0/1
getParameter("name") returns null?
public
class MyServlet extends HttpServlet {
public
void doGet(HttpServletRequest req,
HttpServletResponse res) throws ServletException,
IOException {
String name = req.getParameter("name");
PrintWriter out = res.getWriter();
if (name.equals("admin")) {
out.println("Welcome admin!");
} else {
out.println("Hello, user!");
}
}
}

It will print "Hello, user!".

It will throw a NullPointerException.

It will print "Welcome admin!".

It will not compile.

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 42/44
3/31/25, 1:46 PM STEP Java Assessment

Q.6 Which JSP directive is used to include content from another file at the 0/1
translation time?

<jsp:include />

<%@ include file="..." %>

<%@ page include="..." %>

<jsp:forward page="..." />

Correct answer

<%@ include file="..." %>

Q.7 Which of the following tag libraries is used for JSTL (JavaServer 1/1
Pages Standard Tag Library)?

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/html" prefix="h" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/jsp" prefix="jsp" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/beans" prefix="b" %>

Feedback

Option A is Correct

This form was created inside NJ Group.


Does this form look suspicious? Report

Forms

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 43/44
3/31/25, 1:46 PM STEP Java Assessment

https://docs.google.com/forms/d/e/1FAIpQLSfJ5TAYVPif8XU6XR3HdLbU4Yi98XFFHGkDyUR_I-cfreOrYQ/viewscore?vc=0&c=0&w=1&flr=0&viewsc… 44/44

You might also like