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

Week-01 - Assignment

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)
21 views

Week-01 - Assignment

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/ 7

NPTEL Online Certification Courses

Indian Institute of Technology Kharagpur

PROGRAMMING IN JAVA
Assignment 1
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10 × 1 = 10

QUESTION 1:
Which of the following is NOT a primitive data type in Java??
a. int
b. boolean
c. String
d. char
Correct Answer: c

Detailed Solution:

String is not a primitive data type.


__________________________________________________________________________

QUESTION 2:
Consider the following program.

public class Question{


public static void main(String[] args){
byte x = 127;
x++;
++x;
System.out.print(x);
}
}

What is the output of the above code?


a. 127
b. -127
c. 129
d. 2
Correct Answer: b
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Detailed Solution:

Range of byte data in java is -128 to 127. But the byte data type in java is cyclic in nature.
___________________________________________________________________________

QUESTION 3:
Which of the following concept that Java doesn’t support?
a. inheritance
b. encapsulation
c. pointer
d. array

Correct Answer: c

Detailed Solution:

Java does not support pointer.


______________________________________________________________________
QUESTION 4:
Which of the following is not a keyword in java?

a. import
b. super
c. method
d. class

Correct Answer: c

Detailed Solution:
Here, import, super and class are reserved keywords in Java, which cannot be used for naming a
variable or class.

______________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 5:
Consider the following program.

public class Question{


public static void main(String[] args){
int[] x = {12, 20, 015};
for(int i = 0; i < x.length; i++){
System.out.print(x[i] + " ");
}
}
}

What will be the output of the program if it is executed?


a. 12 20 13
b. 12 20 15
c. 12 20 015
d. 12 20 F

Correct Answer: a

Detailed Solution:

015 is an octal number, its equivalent decimal number is 13.

______________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 6:
Match the following java terms with their descriptions?

A. JDK 1. A software development kit that provides all the necessary


tools and libraries to develop, compile, and run Java applications.

B. JRE 2. A software package that provides the necessary runtime


environment for executing Java applications.

C. JVM 3. An abstract machine that executes java bytecode.

Choose the correct option.

a. A-1 , B-2, C-3


b. A-2 , B-3, C-1
c. A-3, B-2 ,C-1
d. A-3, B-1,C-2
Correct Answer: a

Detailed Solution:

Option a is correct.

______________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 7:
Consider the following program.

public class Question{


public static void main(String[] args){
short x = 20;
x = x * 2;
System.out.print(x);
}
}

What will be the output of the program if it is executed ?


a. 20
b. 2
c. Compiler error
d. 40

Correct Answer: c

Detailed Solution:

This will give compile error - “Lossy conversion from int to short”.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 8:
What is the output of the following code ?

public class Question{


public static void main(String[] args){
boolean x = true;
boolean y = false;
boolean z=(x==y);
System.out.println(z);
}
}

a. null
b. true
c. false
d. 1

Correct Answer: c

Detailed Solution:
Test by run.

_____________________________________________________________________

QUESTION 9:
Which program is used to compile Java source code into bytecode?

a. javap
b. javac
c. java
d. javad
Correct Answer: b

Detailed Solution:
The JDK includes a tool, ‘javac’ that compiles from Java source code to a target of Java bytecodes.
The program ‘java’ is used to execute Java bytecode. Note that there is no program like ‘javap’
and ‘javad’.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

_____________________________________________________________________

QUESTION 10:
Consider the following program.

public class Question{


public static void main(String[] args){
int x = 5;
x *= (2 + 8);
System.out.println(x);
}
}

What will be the output of the program if it is executed ?


a. 50
b. 10
c. Compiler error
d. 5

Correct Answer: a

Detailed Solution:

Here, x* = 2 + 8 is equivalent to x * (2+ 8) = x * 10. Therefore, x = 50.

******

You might also like