java SE8 developer
java SE8 developer
Which of the jump statement can skip processing of one iteration if a specified condition ocuursnand process
with the remaining iterations?
a. break
b. return
c.continue
d.exit
Answer: continue
a.Queue
b.Enque
c.Deque
d.ArrayDeque
Answer: Enque
3. which among the following option are correct with respect to Hashmap(select 2 options)
b.override to(String)
4.which of the below method name is valid as per java naming convention?
a.METHOD_NAME
b.MethodNAme
c.methodName
d.Method_Name
Answer: methodName
5.which one of the following is not used for the automatic accurate tracking for the decimal values?
a.float
b.double
c.BidDecimal
d.Decimal
6. what is the magic number in java in the concept of java programming best practices
7.which of the following mechanism in OOP is a process of hiding certain details and showing only essential
information to the user?
a.polymorphism
b.encapsulation
c.abstraction
d.inheritance
Answer: Abstraction
a.An error shows a serious problem which should not be caught by an application
b.An error usually occurs due to lack in any of the system resources
if(flag = true) {
system.out.println("true");
else {
system.out.println("false");
a.true
b.false
c.true false
Answer: true
10.which of the following comes under compile time polymorphism in java(choose any 2)
a.method overloading
b.Constructor overloading
c.Method overriding
d.constructor overriding
(ii) an abstract class is designed only to act as a base class in hierarchy to be inherited by other class
a.only(i)
b.only(ii)
13.which of the following interface should be implemented by a resource if we want to create a resource part of
try block
a.closeable
b.closeable<E>
c.AutoCloseable
d.AutoCloseable<E>
Answer: AutoCloseable
b.unique ID of an object
a.collection
b.Iterable
c.List
d.Map
Answer: List
list.add(22);
list.add(23);
method(list);
system.out.println(list);`
a.[22,23]
b.[23,22]
c.compilation error
d.[22.0,23.0]
a.the code will not be compiled due to static method of an interface cannot be overriden
b.the code will not be compiled as two interface has same name for the static method
c.the code will not be compiled we have to override the static method in the class to avoid the diamond
problem
Answer: the code will not be compiled due to static method of an interface cannot be overridden
c.Map<Integer,String>employeeData=new LinkedHashMap<>();
@Test
assertSame(1,2);//line 2
b. test fails as fail() Is meant for failing the test case explicity
20. what is the scope/access specifier of getEmployeeId() method in the code snippet given below?
Class Employee {
Int employeeId;
double getEmployeeId() {
System.out.println(“Employee Id”);
Return employeeId;
a. public
b. private
c. protected
d. default
Answer: private
int i = 5;
switch(i) {
case 1:
System.out.println(“One”);
Break;
case 2://line1
case 3://line 2
case 4,5://line 3
default
System.out/println(“Default”);
Answer: It will work fine and display “four and five” as output
22. what is the result of attempting to compile and run this program?
class Demo {
if(f1>f2) {
else {
a. f1 is bigger than f2
c. no output
d. null
Select the best code to be used to iterate through the “customerList” object data.
1. for(iterator itr=customerList.iteration();itr.hasNext(); {
System.out.println(itr.hasNext());
2. for(String s:customerList)
System.out.println(s);
3. for(iterator itr=customerList.iteration();itr.next();) {
System.out.println(s.next());
}
4. for(iterator itr=customerList.iterator(customerList.size());itr.hasPrevios();) {
System.out.println(s.previos());
}
a. option 1
b. option 2
c. option 3
d. option 4
Answer: Option 2
24. Given:
class Invoice {
try {
count++;
throw new Exception();
} catch(Exception ex) {
Count++;
Void display() {
inv.nillNo();
inv.display();
25. which of the below ‘if’ statement can be used to find a year is a leap year or not?
27. which of the below code is implemented without best practices standard?
List strList=Arrays.asList(str);
for(iterator itr=strList.iterator();itr.hasNext();) {
System.out.println(i1==i2);
a. option(1) doesn’t follow best practices can be improved using for(String s:strList)
b. option(2) doesn’t follow best practices as objects should not be compared with ==
String s1 = "Thank",s2="Thank";
a. x==y.false
x<=y.false
s1==s2.true
boo==true false
b. x==y.false
x<=y.false
s1==s2.true
boo==true true
c. x==y.true
x<=y.false
s1==s2.false
boo==true true
d. x==yfalse
x<=yfalse
s1==s2false
boo=true true
ANSWER:
x==yfalse
x<=yfalse
s1==s2false
boo=true true
29.Which among the following option are correct with respect to HashMap(Select 2)
a) Override Boolean equals(Object o)
b) Override toString()
c) Override int hashcode()
d) Override String hashCode()
Answer:Override Boolean equals(Object o), Override int hashcode()
30.
}
}
a. 1
null
b. 3
null
c. 2
movie3
ANSWER: 3 Null
ANSWER: {1,3{1,3,2}}
32.
public static void main (String [] args) {
TreeSet set = new TreeSet<>();
set.add("a");
set.add(6);
set.add("c");
Iterator ite = (Iterator) set.iterator();
while(ite.hasNext()) {
System.out.println(ite.next()+" ");
}
}
a. a 6 c
b. a followed by exception
c. The code will give compile time error cannot add String
ANSWER: The code will give Compile time error cannot add string
String s=” “;
Assert.assertNotNull(a);
a. Test passes
b. Test fails
d. Compilation fails
@Test//line2
assertTrue(list.isEmpty());
Which of the following statement is true regarding the above code fragment?
c. If we replace line1 by ’privateArrayList list=new ArrayList<>();’ the test case will pass
Answer: If we replace line1 by ’privateArrayList list=new ArrayList<>();’ the test case will pass
d. Abstract class
36.Which of the below methods can be defined in a single class in java? Select the most suitable option
a. 1 and 3 together
b. 1 and 2 together
c. 2 and 3 together
Calculator.java
return a+b;
Identify the option to write the TestCase for the add method?
b. Test case should be in the different package of Target Class as public void testAdd()
c. Test case should be in the same package of Target Class as public void testAdd()
d. Test case should be in the same package of Target Class as protected void testAdd()
Answer: Test case should be in the same package of Target Class as protected void testAdd()
38.Given:
Int i1=15;
String b1=i1>20?”Green”b1>10?”Blue”:”Voilet”;
System.out.println(b1);
a. No output
b. Green
c. Blue
d. Voilet
Answer:Blue
b. An error usually occurs due to the lack in any of the system resources
Answer: An error usually occurs due to the lack in any of the system resources
Errors can be handled by the code of the program
40.Select the outcome of the below code snippet:
int i=34;
int j=34;
System.out.println(i==j);
System.out.println(i1==i2);
a. True true
b. True false
Answer: Compilation error [wrapper classes cant be compared using==] will be thrown
2. This pattern involves a single class which is responsible to create an object which make sure that only
single object gets created
3. Singleton class provides a way to access the object directly without the need to instantiate the object
of the class
a. Only statement 1
b. Only statement 2
c. Only statement 3
42.which of the following can be written in line 1 as per best coding practices?
for(int i=0;i<arr.length;i++)
//line 1
System.out.println(“name of a language”);
} else {
t.show();
b. If(arr[i].length()==4 | arr[i].equals(“java”))
d. If(arr[i].length()==4 || arr[i].equals(“java”))
43.Given
Interface Greeting {
Obj.greet();
a. In Greet interface
In GreetingDef class
b. In GreetingDef class
c. In GreetingDef class
In Greet interface
d. In greet interface
44. Given
Util.java
return str1+str2;
UtilTest.java
@Test
//line1 {
//set of statements
a. void testConcatenate()
45. Given
twoD[0]=new int[1];
twoD[1]=new int[2];
twoD[2]=new int[3];
twoD[3]=new int[4];
for(int i=0;i<4;i++) {
for(int j=0;j<i+!;j++) {
twoD[i][j];//line2
}
System.out.println(“executed”);
String first=”abc”;
String second=”abc”;
@Test
public void StringAssertEquals() {
Assert.assertEquals(third, fourth);
}
@Test
public void StringAssertSame() {
Assert.assertSame(first, second);
}
@Test
public void StringAssertSames() {
Assert.assertEquals(third, fourth);
}
}
47. what changes need to be made in the following code to make the singleton pattern correct? (any 2)
48. From the below options, identify the methods and constructors in throwable that support chained
exceptions:
1. throwable getCause()
2. throwable initCause(throwable)
3. throwable(String, throwable)
4. throwable(throwable)
50. what is the output when the below code is compiled and executed?
a. 1265
1234
b. 1265
1265
c. 1265
1212
Answer:1265
1212
Interface Parking {
Static void Prk() {
System.out.println(“from parking interface”);
}
}
public class CarParking implements Parking {
static void park() {
system.out.println(“from CarParking class”);
}
public static void main(String[] args) {
Parking.park();
Park();
}
}
What will be the output of the code after execution?
a.Assert.assertSame(tc.display(88), ‘A’);
Assert.assertSame(tc.display(64), ‘F’);
Assert.assertSame(tc.display(100), ‘F’);
b.Assert.assertSame(tc.display(88), ‘A’);
Assert.assertSame(tc.display(64), ‘F’);
c. Assert.assertSame(tc.display(85), ‘A’);
Assert.assertSame(tc.display(64), ‘F’);
Assert.assertSame(tc.display(84), ‘B’);
d.Assert.assertSame(tc.display(85), ‘B’);
Assert.assertSame(tc.display(84), ‘F’);
Assert.assertSame(tc.display(74), ‘A’);
1. Class AccessModifier
{
public int y = 20;
float z = 30;
protected int a = 20;
private int b = 20;
}
Identify the order of the variables based on the visibility from high to low.
a. yazb
b. azby
c. zaby
d. abyz
2. class Parent{
public final void show(){
System.out.println(“show() inside Employee”);
}
}
What will be the output when the above code is compiled and executed?
Answer : show() inside Unit
100
3. class Greeter{
public static void main(String[] args) throws Exception {
try{
System.out.println(“Greetings!!”+” “+args[0]);
}catch(ArrayIndexOutOfBoundsException e){
System.out.println(“Sam”);
}
}
Predict the output?
a. Greetings!! Sam
b. Sam
c. Compilation error
d. Runtime error
4. class Expression
{
public void calc(){
double x = 10;
int y = 20;
float z = 30;
//line 1
b = x+y+z;
}}
7. class Book{
public static void main(String[] args) throws Exception{
System.out.println(“Invoke “+jsp());
}
static String jsp(){
try{
throw new IOException(); }
catch(IOException e){
return “IO”; }
finally{
return “Finish”;
}}}
Predict the output
a. Invoke IO
b. Invoke IO
Invoke Finish
c. Invoke Finish
d. The code will give compilation error as jsp() has not returned any value
8. public class WrapperClassDemo{
public static void main(String aa[])
{
Integer intWrapper = Integer.valueOf(“12345”); //line 1
Integer intWrapper2 = Integer.valueOf(“11”,2); //line 1
Integer intWrapper3 = Integer.valueOf(“E”,16); //line 1
System.out.println(intWrapper+” ”+intWrapper2+” “intWrapper3);
}
}
Predict the output
a. 12345 11 E
b. 12345 11 14
c. 12345 3 14
d. Runtime Error in Line 3 due to NumberFormatException
9. Which of the following pattern refers to creating duplicate object while keeping
performances in mind?
a. Builder Pattern
b. Bridge Pattern
c. Prototype Pattern
d. Filter Pattern
a. “super” keyword can be used to call a parent class public constructor which is
present in a different package
b. “super” keyword can be used to call a parent class private constructor which is
present in the same package
c. “super” keyword can be used to call a parent class protected constructor which is
present in the same package
d. “super” keyword is used to call a parent class protected constructor which is
present in a different package
11. Which among the following is valid option for wildcards?(Select 2 options)
a. Used to relax restriction on the variable
b. Used in scenario where type being operated upon is not known
c. Used in generic method type argument
d. Can access members of super class
12. class Message{
public static void main(String[] name) throws Exception {
Integer[][] val = { {10,12,14}, {null}, {18,20,22} };
System.out.println(“Array of = “+val[1][1].intValue());
}}
13. Which of the following statements are correct w.r.t Java version 8 (select two)
a. The JDK will be installed as part of the JRE installation
b. The JRE includes the Java tool which launches the JVM to execute the Java
program
c. JDK can also be installed without JRE
d. JRE installable’s are available for different platforms like Windows and Linux
14. Which among the following comes under Creational Design Pattern?
a. Iterator Design Pattern
b. Singleton Design Pattern
c. Command Pattern
d. Observer Design Pattern
18. What is the result of attempting to compile and run this program?
21. All the wraper Classes (Character, Boolean, Byte, Integer, Double, Long, Short, Float)
extends which interface/class ? (Select 2)
a. Serializable
b. Number
c. Comparable
d. BufferedReader
22. Which among the following code snippets are illustrating the concept of autoboxing
here? (Choose 2)
a. Character ch = ‘a’;
b. ArrayList<Integer> listOfTickets = new ArrayList<> ();
listOfTickets.add(101);
listOfTickets.add(102);
c. Int var1 = new Integer(1003);
d. ArrayList arrayList = new ArrayList();
Int number = arrayList.get(0);
a. OutOfStackError
b. OutOfMemoryError
c. VirtualMachineError
d. StackOverFlowError
24. From the below options identify the methods and constructors in Throwable that
support chained exceptions.
1. Throwable getCause()
2. Throwable initCause(Throwable)
3. Throwable(String, Throwable)
4. Throwable(Throwable)
25. Which of the following method of Assert class checks that a condition is false?
a. if(firstName == “Annie”)
b. if(firstName.equals(“Annie”))
c. if(firstName.equals“Annie”) && salary==50000)
d. if(firstName == “Annie” | !salary==50000)
27. How can you find out the difference between two dates?
a. Date1.difference(date2)
b. Date1.until(date2,TemporalUnit);
c. Date1.between(date2);
d. Date1.minus(date2);
a. 08-06-2020
b. 07-Jun-2020
c. 08-Jun-2020
d. 09-06-2020
4. Given
Public class Sample{
Public static void main(String[] args) throws Exception{
Try{
System.out.println(“In try block”);
System.exit(0);
}catch(Exception ex){
System.out.println(“In catch block”);
Ex.printStackTrace();
}finally{
System.out.println(“In finally block”);
}
}
}
Predict the output?
Ans: In try block
5. Which of the following are the advantages of exception handling in Java(Choose any 3 options)?
(i) To maintain the normal flow of execution
(ii) Meaningful error reporting
(iii) To document compile time error
(iv) To prevent the abrupt termination of a program
10. Which among the following is/are true about Design Pattern
i. Design pattern depends upon abstraction
ii. Design patterns are completed designs that can be transformed directly into code
iii. Design pattern depends on abstraction, follows the process of Dependency Injection
iv. Design pattern is a template of solving problem that can be used in many real world
software development
Ans i & ii
11.From the below options identify the methods and constructors in Throwable that support chained
exceptions
i. Throwable.getCause()
ii. Throwable.initCause(Throwable)
iii. Throwable(String, Throwable)
iv. Throwable(Throwable)
Ans: Option2
Ans Option ii
14. Which among the following option are correct with respect to HashMap
I. Override boolean equals(Object o)
II. Override toString()
III. Override int hashCode()
IV. Override String hashCode()
15. Which of the foll interfaces are not a part of java collections framework(choose any2)
i. List
ii. Queue
iii. SoretdList
iv. ArrayList
16. Where are string objects stored in memory using “new” keyword?
i. In Stack Memory
ii. In String constant pool in Heap Memory
iii. In Native Methods stack Memory
iv. Anywhere in Heap Memory
Ans iv
17. What will be written at the line1 so that the below code will compile and run successfully?
18. Given
public class Employee{
private String roles;
Public Employee (String role) {this.role= role;}
Public Boolean equals (Employee emp){return emp.role.equqls(this.role)
}
}
Which among the following are correct with respect to the above code(Choose 2)
I. Code give compilation error due to private attribute emp.role cannot be accessed
II. Object.equals() method is not properly overriden
III. Code will compile successfully
IV. hasCode() method implementation is required
//Line1
System.out.println(“catch exception”);
}finally{
System.out.println(“finally”)
}
}
}
I. Car car = new Car();
System.out.println(“try block”)
Select a valid implememntation of getCustomerType method in another class from the below
options
d. new Customer(){
return “Premium”;}
Ans: a & c
@After
Public void before(){
System. Out.println(3)
}
@Test
Public void test(){
System. Out.println(5)
}
@Before
Public void fter(){
System. Out.println(4)
}
@AfterClass
Public static void afterClass(){
System. Out.println(2)
}
Ans Option 1 :
1
4
5
3
2
23. Which of the following is ‘FALSE’ regarding ‘super’ keyword in Java?
Option3, Super keyword can be used to call a parent class protected constructor which is
present in the same package
26. How many number of values can be accommodated by the varargs in java
28. Have a look at the foll code and choose the correct option
Class ReportUtil{
Int reportId =0;
Static {++reportId}
Static int employeeReportId;
Public void preReport(){
employeeReportId= reportId;
}
}
Ans: option 3 The code will not get compiled as instance variable cannot be reffered from the
static block
29. Which of the below methods can be defined in the single class in java. Select most
suitable(select 2 options)
1. Void add(int,int)
2. Void add(int,int, int)
3. int add(int,int)
I. 1 & 3 together
II. 1 & 2 together
III. 2 &3 together
IV. 1,2 &3 together
Ans Options ii and iii
30. Ria has a class called Account.java under two separate packages com.infy.debit and
com.infy.credit. Can she use the Account classof both the packages in another class called
ReportUtiljava of package com.infy.util
Option2: No, She cannot as there will be a compilation error stating that the import collides with
another import
31. Which of the following are true about enums in Java? (Choose 3 correct)
I. enums can implement any other interface in java
II. an instance of enum can be created outside of enum itself
III. enum cant extend any other class except the abstract base class java.lang.enum
IV. enum can be used to implement singleton design pattern
32. What’s is true with respect to abstract class being given below
33. Which of the following are NOT good practice for creating objects.
a. Lazy initialization of objects
b. Creating String literals instead of String objects
c. Creating Wrapper objects instead of primitives
d. invoking static factory methods for immutable classes
Ans option c
34. Which among the foll are valid lamda expressions to sort the numbers in numberlistin
descending order choose 3
a. numberList.sort((x,y)->x.compareTo(y))
b. numberList.sort(int x,int y)->x.compareTo(y))
c. numberList.sort((x,y)->{return x.compareTo(y))}
d. numberList.sort((Integerx,Integer y)->x.compareTo(y))
Ans
35. What is the output for the below code
for(int i:x)
System.out.print(i+"");
System.out.println();
}
void func(int a) //Line1
{ System.out.println("one"); }
Ans:Option B
Number of arguments1
150
Number of arguments4
11121314
Number of arguments0
37. Given
HashMap <Integer, Integer> myMap = new HashMap<Integer, Integer>();
myMap.put(1001,5);
myMap.put(1002,8);
myMap.put(1002,5);
myMap.replace(1002,5, 100);
system.out.println(myMap)
}Catch(Student st){
System .out.println(“Student class Exception”);
}catch (Hosteller host){
System .out.println(“Hosteller class Exception”);
}
}
}
Ans: The code will not compile Unreachable catch for Hosteller because Student
class exception is caught before Hosteller
39.
class Operations{
Public void addition(){}
}
{}
}
Line 1 generates compilation error . which of then below option helps to resolve this
class EmployeeUtil {
//line1
double amountTax;
public double taxCalculator(double salary)
{
amountTax = salary *TAX_PERCENTAGE/100;
return amountTax;
}
}
public class ConstantMain
{
public static void main(String[] args) {
System.out.println(new EmployeeUtil().taxCalculator(5000));
}
}
Ans:
41.
interface Component {
String cname = "Motor";
String getName(String name);
}
}
}
42.
}
}
43. Which of the following regarding an abstract class is/are true in Java
44.
public class CodeForException {
//public static void main(String[] args) {
public void callMe() throws Exception{
try
{
int value=3/0;
}
catch (ArithmeticException aa)
{
System.out.println(aa);
}
}
public void calling()
{
callMe();
}
}
45.
public Demo(){
if(id ==null){ {
}
id = "ACC1101"+ Math.abs(random.nextInt());
}
}
}
}
Ans - if(id==null){
46. Given
//Assume all the required imports are added
Which of the following statement is true regarding the above code fragment?
47.
public static void main(String args[])
{
HashMap<Integer, Integer> myMap = new HashMap<Integer, Integer>();
myMap.put(1001, 5);
myMap.put(1002, 8);
myMap.put(1002, 5);
myMap.replace(1002,5,100);
System.out.println(myMap);
}
48. what is the result when the following code snippet is compiled?
class Student extends Exception{}
class Hosteller extends Student{}
public class StudentTester {
public static void main(String[] args){
try{
//some monitored code
throw new Hosteller();
}
catch (Student st){
System.out.println("Student class exception");
}
catch (Hosteller host){
System.out.println("Hosteller class exception");
}
}
Ans: The code will not compile Unreachable catch for Hosteller because Student
class exception is caught before Hosteller
49.
class Operations
{
public void addition()
{}
}
class AdvOperations extends Operations {
void addition()//Line1
{}
Line 1 generates Compilation error. Which of the below options helps to resolve
this?
50.
System.out.println(“Main1”)
System.out.println(“Hello Main”)
}
}
}
}
}
Ans:
0
12
345
6789
53. which of the following keyword is used to prevent the content of a variable from
being modified from outside.
Ans - Final
54.
class Book{
int bookid =2356;
}
class Book1 extends Book{
int bookid = 1167;
}
class Book2 extends Book1{
int bookid = 2378;//Line8
void display(){
System.out.println(super.super.bookid);//Line10
System.out.println(super.bookid);//Line11
System.out.println(bookid);
}
}
public class Demo2 {
public static void main(String[] args){
Book2 book2 = new Book2();
book2.display();
}
}
55. Consider the below class and identify the extension of the output file when we
execute the command javac Employee.java
class Employee1 {
private int x=10;
public void showX(){
System.out.println(x);
}
}
Ans - .java
56. which of the below if statement is used to find a year is a leap year or not
Ans: if((y%4==0) && (y%100 !=0) || (y%400==0))
57. Analyze the below code and predict the output when executed the code
}
}
Ans: Compilation error in line 2 as super keyword cannot be used in static context
58. have a look at the following class and predict what should be placed at line 1 to
get 150.0 as output when the code gets executed? (choose 2 options)
class EmployeeUtil{
//line1
double amountTax;
public double taxCalulate(double salary){
amountTax = salary*TAX_PERCENTAGE/100;
return amountTax;
}
}
public class ConstantMain{
public static void main(String[] args){
System.out.println(new EmployeeUtil().taxCalulate(5000));
}
}
Ans:
60. Which of the following statements regarding an abstract class is/are true in Java
61. which of the following is valid function used to read values using Scanner in java (choose 3)
1. nextInt()
2. nextChar()
3. nextLong()
4. nextLine()
package Example;
package java.pac;
import Example.Pet;
public class Dog extends Pet{
@Override
public void displayName(){
System.out.println("Inside Dog");
}
package com.infy;
import Example.Pet;
public class Demo7 {
public static void main(String[] args){
Pet pet = new Dog();//Line1
pet.displayName();
}
Ans Option D
66. which are valid upper bound by class Employee of list. (Doubt)
Choose any 2
}catch(NullPointerException ex) {
System.out.println("Exception is caught here");
Ans:
//a, b
interface Book {
static void bookNmae() {
System.out.println("in interface book");
}
}
Creational Pattern
Structural pattern
Behavioral Pattern
Java pattern
Section 1:
}
}
Ans – No She cannot as there will be compilation error stating the import collides with another import.
Ans – double
6. What is the result when the following code is compiled and executed?
class Demo {
int x=1;
int y=2;
Demo display(Demo demoParam){
Demo obj = new Demo();
obj = demoParam;
obj.x = demoParam.x++ + ++ demoParam.y ;
demoParam.y = demoParam.y;
return obj;
}
public static void main(String[] args){
Demo obj1 = new Demo();
Demo obj2 = obj1.display(obj1);
System.out.println("obj1.x = " + obj1.x + "obj1.y = " + obj1.y);
System.out.println("obj2.x = "+ obj2.x + "obj1.y = " + obj2.y);
}
}
Ans:
obj1.x = 4obj1.y = 3
obj2.x = 4obj1.y = 3
7. Have a look at the following class and predict the option that is correct?
public class CodeForException {
public void callMe() throws Exception{
try{
int value = 3/0;
Ans: The code will face issues during compilation as the calling code neither handles nor throws
Exception
Ans – 15,12
}catch(Exception e){
name+="hn";
}finally{
name+="s";
empName();
name+="on";
}
System.out.println(name);
}
static void empName(){
throw new NullPointerException();
}
}
Ans – The code will give java.lang.NullPointerException in finally block when executing
10. What is the result when the code is compiled and executed?
class Calculator {
int a = 123, b=200;
public void display(){
System.out.println("a:" + a + "b:" + b+"");
}
}
class CalculatorDemo{
public static void main(String[] args)
{
Calculator calculator1 = new Calculator();//Line1
Calculator calculator2 = calculator1; //Line2
calculator1.a+= 1;
calculator1.b+= 1;
System.out.println("calculator1 values:");
calculator1.display();
System.out.println("calculator2 values:");
calculator1.display();
}
}
Ans –
calculator1 values:
a:124b:201
calculator2 values:
a:124b:201
Section2
1. What can be expected when the following code is compiled
abstract class Customer {
Ans: Option A: Compilation error in line2 as static method cannot be called with
object reference
6. Given below. What will be the output when code is compiled and executed
public class Parent {
}}
Ans: Option D
100
}}
Ans: Option B
I am a trainer
I train Java.
I want to learn Java
I am a trainee
I train Java.
I want to learn Java
10. Given
Class Parent{}
Class Child extends Parent{}
Final class GrandChild extends Child{}
Which of the following statement is not ‘true’ about the above code.
Ans : Option C: Reference of parent class can accept the instance of child class but not the
instance of GrandChild class
Section 3
1. What will be the output of the below code
String stuName="Jacklin";
}
catch (Exception e) {
throw new Exception();
}
finally
{
stuName+="Hello" +stuName;
}
stuName+="!!!!";
}
Ans Jacklin--HelloJacklin--!!!!
Option D
}catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Sam");
}
}
}
Ans: Option A: 5
4. Given
Public class Sample{
Public static void main(String[] args) throws Exception{
Try{
System.out.println(“In try block”);
System.exit(0);
}catch(Exception ex){
System.out.println(“In catch block”);
Ex.printStackTrace();
}finally{
System.out.println(“In finally block”);
}
}
}
Predict the output?
Ans: Option B.In try block
5. Which of the following exceptions are ignored during compile time (choose any 2 option)
Option A and C
ArrayIndexOutoFBoundException
NullPointerException
Section 4
1. Identify the outcome of the given code snippet
Ans :
Option D New Array[11, 22, 33, 7, 44, 55, 66, 77, 88, 99]
2.Which of the following are true about enums in Java? (Choose 3 correct)
I. enums can implement any other interface in java
II. an instance of enum can be created outside of enum itself
III. enum cant extend any other class except the abstract base class java.lang.enum
IV. enum can be used to implement singleton design pattern
Ans Options i, iii & iv
4. Given
public class App{
Section 5
1.What will happen when the following code is executed?( Output – not sure)
public class TestDemo{
2. Which among the following option are correct with respect to HashMap
Override boolean equals(Object o)
Override toString()
Override int hashCode()
Override String hashCode()
}
}
Ans --- A C B
Section 6:
1.What is true regarding the following code snippet
4. Given
interface Greeting{
default void greet() {
System.out.println("In Greet interface");
}
}
class GreetingDef implements Greeting{
public void greet() {
System.out.println("In GreetingDef class");
}
}
5. The below code will generate compilation error. Select the possible options to
avoid it(Choose 2)
}
public class InsuranceImpl implements Insurance{
public void policyPayment() {
policy();
}
public class App{
public static void main(String[] args) {
new InsuranceImpl().policyPayment();
}
}
Section 7:
1. What is Magic Number in java in the context of java programming best
practices?
2. Given
public class Employee {
private int empId;
private String empName;
private String designation;
private transient String dob;
}
Analyze the given code and identify the suitable comments from the below option.
Ans:
(i) Fields in non-serializable classes should not be ‘transient’
(ii) Make the Employee class as serializable
3. From the below options identify the methods and constructors in Throwable that
support checked exception?
(i) Throwable getCause()
(ii) Throwable initCause(Throwable)
(iii) Throwable (String, Throwable)
(iv) Throwable (Throwable)
4. Identify the valid code needs to be inserted in line5, assume the code is
running in
import java.util.Random;
id = "ACC1101" + Math.abs(random.nextInt());
}
}
public String getId(){
return id;
}
}
Ans - if(id==null){
Section 8:
1. Which among the following comes under Creational Design pattern?
3. What changes need to be made In the following code to make the singleton pattern correct?
(choose 2)
Ans:
Option A &D
A. None the singleton pattern is properly implemented
D. Change the access modifier of employeeinstance from public to private
Section 9:
1. Given
//Assume all the required imports are added
import java.util.ArrayList;
import org.junit.Before;
import org.junit.Test;
Ans -
35[15]
45[15, 15]
2. Which of the following annotation must be used in a test class to run same
test again and again
Ans: @Test
3. Predict the output for the below
//Assume all the required import statements are added
import org.junit.Before;
import org.junit.Test;
import junit.framework.Assert;
Ans:
Test Passed as they point the same object and prints the below in console
in before test1
in before test2
ThJava Question
1. Which of the following is not pre defined annotation in Java?
@Deprecated
@Overriden
@SafeVarags
@FunctionInterface
Ans truefalse
Truetrue
66. Which of the following statements are true if a duplicate element obj T is added to a HashSet?
a) The element obj T is not added and add() method returns false
b) The element obj T is added successfully
c) An exception occurs during runtime
d) An exception occurs during compile time
a) a and b
b) b and c
c) a,b and c
d) a only
Which of the below are NOT good practices for creating objects?
a) Lazy initialization of objects
b) Creating String literals instead of String objects
c) Creating Wrapper objects instead of primitives
d) invoking static factory methods for immutable classes
Which of the below statement indicate the need to use the factory pattern?
Package exceptions;
Public class Demo
{
public static void main(String[] args) {
try
{
return;
}
finally
{
System.out.println("Finally");
}
enum Customer
{
private CUSTID
public CUSTNAME
protected ADDRESS
String stuName="Jackin";
void display()
{
try
{
stuName+="John";
func();
}
catch (Exception e) {
stuName+="GoodName";
}
}
void disp()
{
System.out.println(stuName);
}
}
} Ans Option D (JackinJohn.......!!!!!!GoodName)
}
}
System.out.println("Employee Id");
return employeeid;
}
}
//Line1
System.out.print(day.toString()+"-");
//System.out.print(day.name()+"-");
}
}
SUNDAY-MONDAY-TUESDAY-WEDNESDAY-THURSDAY-FRIDAY-SATURDAY-
Ans : A and C
System.out.print(day.toString()+"-");
System.out.print(day.name()+"-");
}
Ans: C. Compilation fails
which of the below exceptions are mostly thrown by JVM in a Java application?(Choose all that apply)
means runtime exception
a) ClassCastException
b) IllegalStateException
c) NumberFormatException
d) IllegalArgumentException
e) ExcdeptionInitializerError
//Check Tutorial
Ans: Option A Code compiles, runs and produces the output 0.7000003
}
}
Ans:Option D.
show() inside Unit
100
}
}
Ans
Class Employee {
Void disp(Char c) {
Super.disp(c);
new Employee().disp(“D”);
disp(7);
return “Bye”;
emp.disp(“S”);
1. Employee name starts with : S. His experience is : 11 years. Another employee name also starts
with : S. Employee name starts with : D. His experience is : 11 years. His experience is : 7.
2. Employee name starts with : S. His experience is : 11 years. Another employee name also starts
with : S. His experience is 7 years
3. Employee name starts with : S. His experience is : 11 years. Another employee name also starts
with : S. Employee name starts with : D. His experience is
4. Employee name starts with : S. His experience is : 11 years. Another employee name also starts
with : S.
class Dog{
void show(){
System.out.print("Dog");
}
}
class Cat{
void show(){
System.out.print("Cat");
}
}
class BullDog extends Dog{
void show(){
System.out.print("BullDog");
}
}
Ans tricky as runtime error and Implementing type casting also comes. But I guess
more appropriate is runtime error
{
try
{
method();
System.out.print("Inside try");
}
catch (RuntimeException ex)
{
System.out.print("Inside catch(RuntimeException)");
}
catch (Exception ex1)
{
System.out.print("Inside catch(Exception)");
}
finally
{
System.out.print("finally");
}
System.out.print("end");
}
}
public static void method()
{
//Line 26
}
}
Ans: Option A
Square.java
final class Square {
private double length, breadth;
Square(double length, double breadth) {
this.length= length;
this.breadth= breadth;
Square(Square square){
System.out.println("Copy Constructor Invoked");
length =square.length;
breadth= square.breadth;
}
public String toString() {
return "(" + length +"+"+breadth+")";
}
}
Main.java
class Main{
Ans: Option A
class Book
{
private int bookid=231;
private int getBookid()
{
return bookid;
}
return bookid;
//Line1
and
Which of the below option fails at Line 7(choose all that apply)
Employee.java
public class Employee {
SuperDemo.class
void display()
{
//Line7
}
}
class SuperDemo {
public static void main(String [] args)
{
}
Options
i. System.out.println("Maximum Speed"+super.empid);
ii. System.out.println("Maximum Speed"+ new Employee().empid);
iii. Employee emp1 = new Employee();
System.out.println("Maximum Speed"+ new Unit().empid);
iv. System.out.println("Maximum Speed"+ Employee.empid);
Given
The below code fragment can be inserted at Line 1 and Line 2.What will be the output?
ConstructorDemo1 constructorDemo1=new ConstructorDemo1(1101,"Jacklin");
ConstructorDemo1 constructorDemo2=new ConstructorDemo1(1102,"John",25);
class ConstructorDemo1 {
private int id;
private final String name;
static final int age=22;
ConstructorDemo1(int i,String n){
id=i;
name=n;
}
ConstructorDemo1(int i,String n,int a){
id=i;
name=n;
}
void display(){
System.out.println(id+" " +name+" "+age);
}
public static void main(String args[]){
//Line1
//Line2
constructorDemo1.display();
constructorDemo2.display();
}
}
Ans Option B
1101 Jacklin 22
1102 John 22
InnerClassDemo()
{
System.out.print("InnerClassDemo Constructor");
}
Demo.java
class Demo {
Demo()
{
System.out.println("Demo Constructor");
}
public void disp()
{
System.out.print("Simple Class");
}
public static void main(String[] args)
{
InnerClassDemo innerClassDemo=new InnerClassDemo();
innerClassDemo.createDemo();
}
void createDemo()
{
(new Demo() {}).disp();
}
System.out.println("Inside First");
}
public void method(int i,int j) {
System.out.println("Inside Second");
}
public void method(int... k) {
System.out.println("Inside Third");
}
new Main().method(110);
new Main().method(110,210);
new Main().method(110,210,310);//Line1
new Main().method(110110,210,310,410);//Line2
Ans:
Inside Third
Inside Second
Inside Third
Inside Third
class Demo {
class Apple {
Ans Option C.
What code fragment can be inserted at Line3 to enable the code to print188.22
enum Fruits{
APPLE,
MANGO,
STRAWBERRY,
LICHI;
Ans : Option A
double res = Fruits.MANGO.claculate(298, 109.78);
void message()
{
System.out.println("Inside parent class");
}
}
public class Derived extends Parent{
void message()
{
System.out.println("Inside derived class");
}
void display()
{
message();
super.message(); //Line1
}
}
class SuperDemo {
public static void main(String [] args)
{
{
Derived derived=new Derived();
derived.display(); //Line2
}
Ans: Option D.
Inside derived class
Inside parent class
What is the result of attempting to compile and run this program
public class Bank extends Exception{
try
{
throw new Customer();
}
catch(Customer customer) {
Ans : Option C. Compilation error because Customer class exception is not throwable.
}
public static void main(String args[]){
}
}
Book.java
Import java.io*;
Public class ExceptionDemo{
Static class Car implements AutoCloserable{
Public void close(){
System.out.print(“Automatic Door Close”);
}
}
Static class carWindow implements Closerable{
Public void close(){
System.out.print(“CarWindow”);
throw new RuntimeException();
}
}
a. Automatic Door close CarWindow Inside try block inside catch blockfinally
b. Automatic Door Close CarWindow Inside catch blockfinally
c. Inside try blockCarWindowAutomatic Door CloseInside catch blockfinally
d. An exception is thrown at run time
e. Compilation fails
60. Given:
Public class ExceptionDemo1{
Static class Car implements AutoCloseable{
Public void close(){
System.out.print(“Car door close”);
Throw new RuntimeException();
}
}
Static class CarWindow implements Closeable{
Public void close(){
System.out.println(“Car window close”);
Throw new RuntimeException()
}
}
Public static void main(String[] args){
Try{
//Line 1
}
Catch(Exception e){
System.out.println(“Catch exception”);
}
Finally{
System.out.print(“”finally”);
}
}
}
Which of the below code can be inserted at Line1 to display THE OUTPUT AS “try block finally” (Choose
all that apply)
D)system.out.print(“try block”)
Which of the below code fragment needs to be inserted at Line12 to display the output as 15.
public class ExceptionInClass {
int data=10 ;
void calculate() throws Exception
{
try
{
data++;
try
{
data++;
// Line12
}
catch(Exception ex)
{
data++;
}
catch(Exception ex)
{
data++;
}
}
}
void display()
{
System.out.println(data);
}
public static void main(String[] args) throws Exception
{
ExceptionInClass exceptionInClass = new
ExceptionInClass();
exceptionInClass.calculate();
exceptionInClass.display();
}
What is the output when the below code is compiled and executed?
import java.util.regex.Matcher;
import java.util.regex.Pattern;
void turnOn(){
isOn=true;
}
void turnoff(){
isOn=false;
}
}
class LightDemo{
public static void main(String[]args){
Light light1=new Light();
Light light2=new Light();
light1.turnOn();
System.out.println("light1 is on");
light1.turnoff();
System.out.println(light1.isOn);
System.out.println(light2.isOn);
}
}
Ans: True
False
Null
}
public static void main(String[]args){
method();
}
}
Ans: C. Compilation Fails
static int[] x;
static{
x[0]=102;}
public static void main(String[]args){
System.out.println(x);
}
Ans java.lang.ExceptionInInitializerError
for(int i:x)
System.out.print(i+"");
System.out.println();
}
void func(int a) //Line1
{ System.out.println("one"); }
Ans:Option B
one
Number of arguments 4
11121314
Number of arguments 0
How many objects are eligible for garbage collection after executing line8.
public class Employee {
double salary;
public static void main(String[]args){
Employee employee1=null;
Employee employee2=null;
employee1= new Employee();
employee2= new Employee();
employee1= new Employee();
Employee employee3=null;
employee1= employee3=null; //Line8
System.out.println("Hello World");
}
Ans :3 objects
Which statements are true about the following code snippet?(choose all that apply)
Ans : d & a
Ans : b & d
Predict the output
Apple.java
public class Apple {
Mango. Java
@Override
public void color(){
System.out.println("Yellow");
}
public static void main(String[]args){
Apple apple=new Mango(); //Line1
apple.color();//Line2
}
Ans: Yellow
Given:
Select the suitable code fragment can be inserted at Line1(choose all that apply)
private Apple() {
System.out.println("Apple constructor");
void display(){
System.out.println("Apple constructor");
}
}
Ans: Option D: Unresolved compilation problem: The constructor Apple() is not visible
Output of the below code
public class Demo {
static int x=232;
int y=135;
public void display(){
System.out.print("Inside Demo");}
public static void staticMethod(){
System.out.print(x); //Line 8
}
Ans : Option B
232232232Inside Demo
Check line13. If its not Demo.staticMethod(); then answer will be 232232Inside Demo
}
catch(int ex){
System.out.println("Caught Exception" + ex);
}
}
What are the different types of memory areas used by JVM(choose two)?
1.Class
2.Heap
3.Stack
4.Queue
JVM in java is a
1.Debugger
2.Assembler
3.compiler
4.Interpreter
132. What is magic number in java in the context of java programming best practices?
3. Given:
public abstract class Employee {
this.empId = empId;
this.salary = salary;
Which of the following classes provide the right representation of the child class of Employee class?
private int z;
public void display() {
/* code here */
}}
4. Given an abstract Class Customer as below:
{
public abstract String getCustomerType();
Select a Valid implementation of getCustomer Type method in another class, from the below options:
4) new Customer(){
public String getCustomerType()
{ return “Premium”;
}
}
False
Simple
Demo
For
Regular
Expressions
Using
Pattern
Matching
public class RegExDemo {
public static final String string1="Simple demo for "+"regular expressions"+"
usingpatternmatching";
public static void main(String[] args){
//Line 1
//Line2
}
Ans: Option 1
System.out.println(string1.matches("\\t"));
String[] splitString=(string1.split(" "+""));
//(String1.split(\\s+)) not working in my computer so did like this
for(String string: splitString){
System.out.println(string);
}
System.out.println(string1.replaceAll("\\S","\t"));
Select all possible options that are valid among the following Enums can be defined inside____
a) An interface
b) A class {Multiple choice question}
c) A static Context
d) A method
Which code fragment can be inserted at Line 1 to enable the code to print as “Number of Days =25”
class Demo {
public static void main(String[] args)
{
int monthValue=2;
int yearValue=4000;
int numberOfDays=10;
switch(monthValue) {
numberOfDays=25;
else
numberOfDays=28;
break;
default:
System.out.println("Number of Days =" +numberOfDays);
}
}
Ans: Option not clear. Either one can come. Make sure assignment operator is there(= =)
if((yearValue% 4 ==0) &&
(yearValue% 100==0)
||(yearValue% 400==0))
Or
if((yearValue% 4 ==0) ||
(yearValue% 100==0)
||(yearValue% 400==0))
81. Identify which of the following class breaks its input into tokens using a whitespace pattern?
a. InputStreamReader
b. Console
c. Scanner
d. Buffered Reader
e. DataInputStream
Ans : Option C (if pattern.compile and pattern.spilt don’t have dot means then
compilation error)
C)one
two
three
four
five
Which is the correct code fragment to be inserted at Line 1to execute the code to print count starts
from 111,112,113….
public class Demo2 {
public static void main(String[] args){
int[]X={111,112,113,114,115,116,117,118,119,110};
//Line1
System.out.println("count is"+i);
}
}
}
Ans : Option B
for(int i:X){
int a=123;
int b=200;
public void display(){
System.out.println("a"+a+"b"+b+"");
}}
public class CalculatorDemo {
public static void main(String[] args)
{
Calculator calculator1=new Calculator();//Line1
Calculator calculator2= Calculator1//Line2
calculator1.a+=1;
calculator1.b+=1;
System.out.println("calculator1 values");
calculator1.display();
System.out.println("calculator2 values");
calculator2.display();
} }
int i1=0;
int[] j={11,111,14,19,116,215}; //line4
for (int i1:j) //line5
System.out.printf("%d",i1);
}
show()inside Unit
100
Given
Class Parent{
}
Class Child extends Parent{
}
Final class GrandChild extends Child{
}
Which of the following statement is not true about the above code?
a) The above code represents the multi-level inheritance with the two level
b) The GrandChild class can Access the protected and public members of the parent and child class
c) Instance of parent class can accept the reference of the child class but not the reference of
GrandChild class
d) The GrandChild class can override the methods of both Parent class and Child class
In the below code snippet identify which of the following method compares the given values and return
an int which tells lesser or greater
System.out.print(i1.compareTo(i2)+""+Integer.compare(i2,i1)+""+i1.equals(i2)+""+
(i1==i2));
}
}
a) Compare()
b) Equals()
c) compareTo()
d) ==
Output of the below code
Ans A: falsetruefalsetrue
Ans : Option C
First
import java.util.TreeSet;
public class Group extends TreeSet {
Ans : Option A
a) Adding Hans
An exception is thrown at the runtime(java.lang.ClassCastException)
Inside class
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
Ans: Option B
What happens when default keyword is removed from the below code snippet
a) a and b
b) a,b and c
c) c and d
d) b and c
@BeforeClass
public static void beforeClass(){
a=10;
b=new ArrayList();
}
@BeforeMethod
public void int1(){
a=15;
b.add(a);
}
@Test
public void test(){
a=a+20;
System.out.print(a);
System.out.println(b);
}
@Test
public void test1(){
a=a+30;
System.out.print(a);
System.out.print(b);
}
}
class Demo{
public static void main(String[] args){
Pet pet=new Dog();
pet.displayName();
}
}
Ans: Option A
How"are"you?
Integer intWrapper=Integer.valueOf("12345");
Integer intWrapper2=Integer.valueOf("11",2);
Integer intWrapper3=Integer.valueOf("E",16);
System.out.println(intWrapper+" "+intWrapper2+" "+intWrapper3);
}
}
Ans: Option C
12345 3 14
Ans: Option F
null789884577
Which of the below code has to be inserted at Line1, to sort the keys in the props HashMap variable?
public class Demo11{
public static void main(String args[]) {
HashMap props=new HashMap<>();
props.put("key45","some value");
props.put("key12","some other value");
props.put("key39","yet another value");
Set s=props.keySet();
//Line1
} }
}
}
Ans : Option B
B.C.A.
Which of the following code snippet can be inserted at line1 to display the output as
76
Hello
class Apple<A> {
A obj;
Apple(A obj)
{this.obj=obj;
}
public A getObject()
{return this.obj;
} }
class Main{
public static void main(String[] args){
//Line1
}
}
82. Refer the below code snippets and predict the outcome?
@Favourite(“Diary Milk”)
@Favourite(“Kit Kat”)
@Favourite(“5 star”)
@Favourite(“Galaxy”)
public interface Chocolate{
}
@Repeatable(value=Chocolates class)
Public @interface Favourite{
String value();
}
@SuppressWarnings("all") //line1
@SuppressWarnings("deprecation") //line2
public void over()
{
new Date().setDate(00); } }
Ans: Option B.
System.out.println(date1.compareTo(date2));
}
}
int quantity;
}
class Main{
public static void main(String[] args){
Apple apple;
System.out.println("apple quantity");
}
}
What changes are required in the above code for successful execution?
Ans Option A
int x;
int y;
ThisDemo(){
x=45;
y=56;
}
ThisDemo get() //Line1
{
return this;
}
void display()
{
System.out.printf("x=*+x+*y=*+y");
}
}
public class Demo2 implements Demo1{
public void display(String points){};
}
Ans: Option C. compilation of class Demo4 will fail because of an error in line6
List list;
1. public List getList{
if(list.size()==0)
return null;
else
return list;
}
144. //Assume that the first two of three test cases fail in “Testclass”
System.out.println(result.wassuccessful());
1) False
2) True
3) False false true
4) False false false
Ans Option D:
java.programming.course
false,false
Output of following
public interface DefaultMethodInterface1 {
default public void defaultMethod(){
System.out.println("DefaultMethodInterface1");
}
}
checkbox
Ans: Option 1
1. Which of the following OOP terminology associated with java……. Employee has address
Ans - Inheritance
2. What is the result when the following code is compiled and executed
3. Given
@Override
public int compare(Integer o1, Integer o2) {
// TODO Auto-generated method stub
return 0;
}
}
class MovieApp {
public static void main(String[] args){
Integer mov[] = {2019,2017,1989,1994};
Arrays.sort(mov,new Movie());
for (int i:mov){
System.out.print(i+" ");
}
}
Ans – c
2019 2017 1989 1994
Ans: Compilation error in Line 3 as multiple values are not allowed in case
Ans : if (firstName.equals(“Annie”)&&salary==50000)
6. Identify the output of the below code:
Ans – true
7.
Ans - @Test
Ans-JDK
interface Fruits{
public void printPrice();
}
public class Apple {
public static void main(String[] args){
Fruits fruits = new Fruits(){
public void printPrice(){
System.out.println("150");
}
};
fruits.printPrice();
}
}
Ans-150
10. Which among the following is valid option for wildcards?(select 2 options)
Ans:
11. Which of the below method name is valid as per Java naming convention?
Ans: methodName
12. Consider the Junit test class with junit fixture annotations and the methods
as below:
@BeforeClass ---- init()
@AfterClass ---- close()
@Before ---- setUp()
@After ---- tearDown()
@Test----testSum1()
@Test----testEven1()
In which order the methods will execute?
13. Which of the following is the correct syntax to declare the abstract method evaluate?
Ans :
15. Analyze the below code and predict the outcome when compiled and executed?
}
}
Ans – Compilation error in Line2 as super keyword cannot be used in static context
16. Which of the following condition will not allow the finally block to be executed?
18. What is the result of attempting to compile and run this program?
}
Ans – Compilation error because customer class exception is not throwable
19. Which of this statement is not correct and will lead to compilation error…………………….
20. What will be the output of the following code when executed?
public class DateTimeTester {
public static void main(String[] args){
LocalDateTime localDateTime = LocalDateTime.of(2020,5, 13, 20, 46);
System.out.println(localDateTime.get(ChronoField.HOUR_OF_DAY)
+localDateTime.getDayOfMonth());
}
Ans – 33
21. Which of the below code is implemented without best practices standard?
Ans: Option 1 doesnot follow best practices. Can be improved using for(String s:str)
22. Which of the following is used for the automatic accurate tracking for the decimal values:
Ans:BigDecimal
23. Given:
public class TestDemo1 {
public static void main(String[] args)
{
int i=4;
int j=4;
System.out.println(i==j);
Integer w1=new Integer(4);
Integer w2=new Integer(4);
System.out.println(w1==w2);
}
}
Ans: no issues in the above code
1.