Java ST3 B2021 SEM4
Java ST3 B2021 SEM4
CODEQUOTIENT
Q1. thread
1. class priority_thread
2. {
3. public static void main(String args[])
4. {
5. Thread p = Thread.currentThread();
6. System.out.println(p);
7. }
8. }
0
1
4
5
Ans : 5
Q2. What will be the output of the following source code in Java
try {
num1 = 2;
num2 = 40 / num1;
1 of 18 19-05-2023, 07:27 pm
Download | CodeQuotient https://test.codequotient.com/test/getTestContentFile/6454c523f7acf33...
System.out.println(num2);
catch (ArithmeticException e)
catch (Exception e)
System.out.println("To get at the first position, you have to beat the current best strategy. ");
}}
Infinite Value generated The secret behind getting ahead is getting started. There is nothing better than a
stable and focused mind.
20 You need to have a burning desire in you to study
20 You need to have a burning desire in you to study. There is nothing better than a stable and focused
mind
The secret behind getting ahead is getting started. Infinite Value generated There is nothing better than a
stable and focused mind You need to have a burning desire in you to study. There is nothing better than a
stable and focused mind
Ans : 20 You need to have a burning desire in you to study. There is nothing better than a stable and focused
mind
Q3. Strings
1. class myCode
2. {
2 of 18 19-05-2023, 07:27 pm
Download | CodeQuotient https://test.codequotient.com/test/getTestContentFile/6454c523f7acf33...
true
Runtime Error
false
Compilation Error
Ans : false
class A
protected A(String s)
System.out.println("hello");
private Main(String s)
super(s);
System.out.println(s);
3 of 18 19-05-2023, 07:27 pm
Download | CodeQuotient https://test.codequotient.com/test/getTestContentFile/6454c523f7acf33...
hello hi
hi hi
hi hello
compile time error
Ans : hello hi
Q5. MCQ-6
Ans : The Class objects are constructed by the JVM as classes are loaded by an instance of
java.lang.ClassLoader
Q6. MCQ-1-Marks
Compilation error
Runtime error
5656
565
4 of 18 19-05-2023, 07:27 pm
Download | CodeQuotient https://test.codequotient.com/test/getTestContentFile/6454c523f7acf33...
Q7. MCQ-1-Marks
boolean b1 = 1;
boolean b2 = ‘false’;
boolean b2 = false;
boolean b4 = ‘true’
Q8. MCQ-1-Marks
3
0
6
1
Ans : 1
Q9. MCQ-1-Marks
}
}
5 of 18 19-05-2023, 07:27 pm
Download | CodeQuotient https://test.codequotient.com/test/getTestContentFile/6454c523f7acf33...
Q10. MCQ-1-Marks
Q11. MCQ-1-Marks
0
value stored in arr[0].
00000
Class name@ hashcode in hexadecimal form
Q12. MCQ-1-Marks
10. How many copies of static and class variables are created when 10 objects are created of a class?
1, 10
10, 10
6 of 18 19-05-2023, 07:27 pm
Download | CodeQuotient https://test.codequotient.com/test/getTestContentFile/6454c523f7acf33...
10, 1
1, 1
Ans : 1, 10
class Main{
one:two:three
Main:one:two
java:EJavaGuru:one
two:three:four
Ans : two:three:four
_____________________//1
7 of 18 19-05-2023, 07:27 pm
Download | CodeQuotient https://test.codequotient.com/test/getTestContentFile/6454c523f7acf33...
System.out.print(balls[j] + ",");
balls[i] = (i+1)*2;
balls[i] = (i*2);
balls[i] = (i+2)-2;
balls[i] = (i+2)*2;
switch (num) {
default: System.out.println("default");
case 0: System.out.println("case1");
break;
defaultcase1case2
case2
case1
case1case2
8 of 18 19-05-2023, 07:27 pm
Download | CodeQuotient https://test.codequotient.com/test/getTestContentFile/6454c523f7acf33...
Ans : case2
java.util
java.lang
system.lang
java.system
Ans : java.lang
int n = 6;
n = arr[arr[n] / 2];
_____________ //4
Given the following code what will printed if we print the following expression
3
1
5
9 of 18 19-05-2023, 07:27 pm
Download | CodeQuotient https://test.codequotient.com/test/getTestContentFile/6454c523f7acf33...
Ans : 2
Which of the following commands will compile and then print "hello"?
Q19. Exception
Arithmetic exception
Mathematical exception
All
Numerical exception
User has to create a phone book and later on which can be used to query. The phone book contains
entries consists of people's names and their phone number. After that you will be given some person's
name as query. For each query, print the phone number of that person.
10 of 18 19-05-2023, 07:27 pm
Download | CodeQuotient https://test.codequotient.com/test/getTestContentFile/6454c523f7acf33...
Input Format
The first line will have an integer denoting the number of entries in the phone book. Each entry
consists of two lines: a name and the corresponding phone number.
After these, there will be some queries. Each query will contain a person's name. Read the queries until
end-of-file.
Output Format
For each case, print "Not found" if the person has no entry in the phone book. Otherwise, print the
person's name and phone number. See sample output for the exact format.
Code Limits
Sample Input
3 // number of inputs
Ram //name
Gautam
22222
Sham
33333
2 // number of quries
11 of 18 19-05-2023, 07:27 pm
Download | CodeQuotient https://test.codequotient.com/test/getTestContentFile/6454c523f7acf33...
Sample Output
Sham=33333
Not found
ANSWER:
Test case 1 :
Input:
3
Ram
28888
Gautam
22222
Sham
33333
2
Sham
Ravi
Output:
Sham=33333
Not found
Test case 2 :
Input:
1
Ankush
98765
1
Aniket
Output:
Not found
Test case 3 :
Input:
3
vinay
22223
gautam
22222
ram
23232
1
ram
Output:
ram=23232
Test case 4 :
12 of 18 19-05-2023, 07:27 pm
Download | CodeQuotient https://test.codequotient.com/test/getTestContentFile/6454c523f7acf33...
Input:
1
Deepak
12345
2
Deepak
deepak
Output:
Deepak=12345
Not found
Test case 5 :
Input:
4
A
11111
B
22222
C
33333
D
44444
3
D
A
B
Output:
D=44444
A=11111
B=22222
Test case 6 :
Input:
5
AAAAA
11111
AAAAB
22222
AAAAC
33333
AAAAD
44444
AAAAE
55555
2
AAAAB
AAAAE
Output:
AAAAB=22222
AAAAE=55555
13 of 18 19-05-2023, 07:27 pm
Download | CodeQuotient https://test.codequotient.com/test/getTestContentFile/6454c523f7acf33...
You are given a list of student information: ID, First Name, and CGPA. Your task is to rearrange them
according to their ID in the non-decreasing order. No two students have the same ID.
Input Format
The first line of input contains an integer, representing the total number of students. The next lines
contains a list of student information in the following structure:
ID Name CGPA
The name contains only lowercase English letters. The ID contains only integer numbers without
leading zeros. The CGPA will contain, at most, 2 digits after the decimal point.
Output Format
After rearranging the students according to the above rules, print the first name of each student on a
separate line.
Sample Input
33 Rumpa 3.68
85 Ashis 3.85
56 Samiha 3.75
19 Samara 3.75
22 Fahim 3.76
Sample Output
Samara
Fahim
Rumpa
Samiha
Ashis
14 of 18 19-05-2023, 07:27 pm
Download | CodeQuotient https://test.codequotient.com/test/getTestContentFile/6454c523f7acf33...
ANSWER:
Test case 1 :
Input:
5
33 Rumpa 3.68
85 Ashis 3.85
56 Samiha 3.75
19 Samara 3.75
22 Fahim 3.76
Output:
Samara
Fahim
Rumpa
Samiha
Ashis
Test case 2 :
Input:
2
1 Aman 1.2
3 Sunil 2.3
Output:
Aman
Sunil
Test case 3 :
Input:
1
23 Suman 12
Output:
Suman
Test case 4 :
Input:
7
31 Rumpa 3.68
8 Ashis 3.85
5 aman 3.75
9 Samara 3.75
2 aman 3.76
6 sunil 2.2
1 aman 1.2
Output:
aman
aman
aman
sunil
Ashis
Samara
Rumpa
15 of 18 19-05-2023, 07:27 pm
Download | CodeQuotient https://test.codequotient.com/test/getTestContentFile/6454c523f7acf33...
Test case 5 :
Input:
6
31 Rumpa 3.68
8 Ashis 3.85
5 Samiha 3.75
9 Samara 3.75
2 Fahim 3.76
6 sunil 2.2
Output:
Fahim
Samiha
sunil
Ashis
Samara
Rumpa
Test case 6 :
Input:
4
31 Rumpa 3.68
8 Ashis 3.85
5 Kunal 3.75
9 Ravi 3.75
Output:
Kunal
Ashis
Ravi
Rumpa
Q22. Write a Java program in which you need to extend the abstract class in different class like
Rectangle, Circle and Triangle.
You are given a abstract class Shape in which there are two methods are given named display() and
calculateArea(). Write a Java program in which you need to extend the abstract class in different class
like Rectangle, Circle and Triangle.
In the abstract class, the method display() is used to display the area and calculateArea() is used to
calculate the area.
Sample Case:
Input:
16 of 18 19-05-2023, 07:27 pm
Download | CodeQuotient https://test.codequotient.com/test/getTestContentFile/6454c523f7acf33...
Output:
ANSWER:
Test case 1 :
Input:
1
2
3
4
5
Output:
Area of the Rectangle is = 2
Area of the Circle is = 28.259999999999998
Area of the Triangle is = 10.0
Test case 2 :
Input:
3
4
5
6
7
Output:
Area of the Rectangle is = 12
Area of the Circle is = 78.5
Area of the Triangle is = 21.0
Test case 3 :
Input:
1
2
4
6
8
Output:
Area of the Rectangle is = 2
Area of the Circle is = 50.24
Area of the Triangle is = 24.0
17 of 18 19-05-2023, 07:27 pm
Download | CodeQuotient https://test.codequotient.com/test/getTestContentFile/6454c523f7acf33...
Test case 4 :
Input:
2
4
6
4
3
Output:
Area of the Rectangle is = 8
Area of the Circle is = 113.03999999999999
Area of the Triangle is = 6.0
Test case 5 :
Input:
3
4
4
2
3
Output:
Area of the Rectangle is = 12
Area of the Circle is = 50.24
Area of the Triangle is = 3.0
18 of 18 19-05-2023, 07:27 pm