Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
254 views

Week-01Assignmentupdate Java PDF

This document contains a 10 question multiple choice quiz on Java programming from an NPTEL online certification course. The questions cover topics like Java code syntax, object oriented programming concepts, arrays, variables, operators, and if statements. Each question includes 4 multiple choice answers and an explanation of the correct answer.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
254 views

Week-01Assignmentupdate Java PDF

This document contains a 10 question multiple choice quiz on Java programming from an NPTEL online certification course. The questions cover topics like Java code syntax, object oriented programming concepts, arrays, variables, operators, and if statements. Each question includes 4 multiple choice answers and an explanation of the correct answer.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

NPTEL Online Certification Courses

Indian Institute of Technology

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

QUESTION 1:
Which of the following code fragment(s) is/are true?

a. public class Main


{
static public void main(String[] argv) {
System.out.println("Hello World");
}
}
b. public class Main
{
static public void main(String[] args) {
System.out.println("Hello World");
}
}

c. public class Main


{
public static void main(String[] args) {
System.out.println("Hello World");
}
}
d. public class Main
{
public static void main(String[] argv) {
System.out.println("Hello World");
}
}

Correct Answer: a,b,c,d

Detailed Solution:

The modifiers public and static can be written in either order (public static or static public). You
can name the argument anything you want, but most programmers choose "args" or "argv".
NPTEL Online Certification Courses
Indian Institute of Technology

_________________________________________________________________________

QUESTION 2:
Which of the following is not a valid comment?

a. /** comment */
b. /* comment */
c. /* comment
d. // comment

Correct Answer: c

Detailed Solution:
Option c : /* comment .
This is not valid comment statement
___________________________________________________________________________

QUESTION 3:
Which of the following is not an object-oriented programming paradigm?

a. Encapsulation
b. Inheritance
c. Polymorphism
d. Dynamic memory allocation

Correct Answer: d

Detailed Solution:
Dynamic memory allocation is a memory allocation strategy and not a programming paradigm.

______________________________________________________________________________

QUESTION 4:
Which of the following is not a correct statement?

a. It is always necessary to use new operator to initialize an array.


b. Array can be initialized using comma separated expressions surrounded by curly braces.
c. Array can be declared and memory can be allotted in one statement.
d. An array can be declared in one statement and memory can be allocated in other
statement.

Correct Answer: a
NPTEL Online Certification Courses
Indian Institute of Technology

Detailed Solution:
Array can be initialized using both new and comma separated expressions surrounded by curly
braces example : int a [ ] = new int[5]; int [] a; a = new int [10]; and int a [] = { 0, 1, 2, 3, 4};

______________________________________________________________________________

QUESTION 5:
When you compile a program written in the Java programming language, the compiler
converts the human-readable source file into platform-independent code that a Java Virtual
Machine can understand. What is this platform-independent code called?

a. Source code
b. Bytecode
c. Machinecode
d. Opcode
Correct Answer: b

Detailed Solution:

Byte code is an intermediate code between source code and machine code that is executed by an
interpreter such as JVM. e.g., Java class files.
______________________________________________________________________________

QUESTION 6:
Consider the following program.

public class Question{


public static void main(String args[]){
for(int a=1;a<2;a+=1){
System.out.print(a+++a);
}
}
}

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


a. 3
b. 2
c. 4
d. 1
Correct Answer: a

______________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology

QUESTION 7:
Why an array is called “homogeneous collection of data“ in Java?

a. Array cannot store multi-dimensional data.


b. Array has a limited capacity.
c. Array can store only one type of data.
d. Array uses indices for addressing an item.

Correct Answer: c

Detailed Solution: Homogeneous data means a data of same type. And, array can hold only one
type of data i.e. you cannot have an array with items of multiple data type.
_________________________________________________________________________

QUESTION 8:
Which of the following can be used for a variable name in Java?

a. boolean
b. final
c. finally
d. calloc

Correct Answer: d

Detailed Solution:
final, boolean, finally are reserved keyword in Java, which cannot be used for naming a variable
or class.
______________________________________________________________

QUESTION 9:

public class Main{


public static void main(String[] args) {
String str1="NPTEL";
String str2="java";
int a=20;
int b=10;
System.out.println(str1+a+b); //Statement 1

System.out.println(a+b+str2); //Statement 2
}
}
NPTEL Online Certification Courses
Indian Institute of Technology

Which of the following statement(s) is/are correct?


a. The output of the Statement 1 is
NPTEL2010
b. The output of the Statement 1 is
NPTEL30
c. The output of the Statement 2 is
1020java
d. The output of the Statement 2 is
30java

Correct Answer: a,d

Detailed Solution:
+ (plus) operator is overloaded in java.

QUESTION 10:
What will be the output of the following code?
public class Question{
public static void main(String args[]){
if(true){
System.out.print("Welcome");
}
if(1==1){
System.out.print(" to ");
}
if(1){
System.out.print("NPTEL");
}
}
}
a. Welcome
b. Welcome to
c. Welcome to NPTEL
d. Compilation Error

Correct Answer: d

Detailed Solution:

int is not allowed in if(…) construct.

___________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology

You might also like