What will be the output of the below code?
public static void main(String args[]) {
short number = 32767;
short numberTwo = (short)(number + 1);
System.out .println(numberTwo);
Quiz6
Quiz
•
Computers
•
University
•
Hard
Ms. Asst.Prof
Used 1+ times
FREE Resource
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will be the output of the below code?
public static void main(String args[]) {
short number = 32767;
short numberTwo = (short)(number + 1);
System.out .println(numberTwo);
compilation error: cannot convert from int to short
32767
32768
-32768
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
If an arithmetic expression contains variables of int, byte and short data types, what will be the data type of its result?
int
byte
float
short
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will be the output of the below code?
public class Tester {
public boolean checkTemp(int temp) / if (temp > 100) (
return true;
} else {
return false;
}
public static void main(String args []) {
Tester tester » new Tester ();
if (tester.checkTemp(110)) {
System.out.println("Data is valid");
else {
System.out.printin("Data is invalid");
Data is invalid
Data is valid
true
false
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
public class Tester {
pudlic void demoMethod()
int varone = 1000;
float varTwo = 20.00f;
double varThree = 0.0;
varThree = (double) (varTwo + varone * (7.0 / 100));
System.out.println("varThree:" + varThree);
)
public static void main(String args []) {
Tester tester = new Tester();
tester.demoMethod ();
varThree:20.0
varThree:90.0
varThree:1020.0
varThree:0.0
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will the output of the below code?
public class Tester {
public int subtract(int a, int b) {
return (a - b);
public static void main(String args[]) {
int a = 10;
int b = 20;
Tester tester = new Tester ();
int res • tester.subtract(b, a);
System.out.print]n(res);
0
-10
10
Compilation error: the name of the formal and actual parameters must be the same
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Identify the number of instances and local variables present in the Student class given below.
public class Student {
public int rollNo;
public string studentName;
public void findGrade(int marks) {
char grade;
if (marks > 90)
grade = 'A';
else if (marks < 90 && marks > 80)
grade = 'B';
else if (marks < 80 && marks > 70)
grade = 'C';
else
grade = 'D';
System.out.printIn(grade);
}
2 instance variables, 2 local variables
3 instance variables, 1 local variables
2 instance variables, 1 local variables
4 instance variables, 0 local variables
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
public class Tester {
public int add(int a, int b) {
return (a + b);
}
public static void main(String args []) {
int a = 10;
int b = 20;
int sum = 0;
Tester tester = new Tester ();
tester.add(a, b);
System.out.printIn(sum);
}
}
10
0
20
30
15 questions
Java
Quiz
•
University
10 questions
java quiz on Encapsulation and Abstraction
Quiz
•
University
10 questions
CSI U5L2 - Sequence & Selection
Quiz
•
10th Grade - University
10 questions
Methods
Quiz
•
University
14 questions
Java Operators
Quiz
•
University
10 questions
Talent Next Java MCQ-1
Quiz
•
University
10 questions
exception
Quiz
•
University
15 questions
Java Method
Quiz
•
University
15 questions
Character Analysis
Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing
Quiz
•
9th - 12th Grade
10 questions
American Flag
Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension
Quiz
•
5th Grade
30 questions
Linear Inequalities
Quiz
•
9th - 12th Grade
20 questions
Types of Credit
Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25
Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers
Quiz
•
6th - 8th Grade