Table of Contents
NPTEL Programming in Java Assignment 4 Answers (Week 4)
Q1. Which of the following is the correct statement for creating a package?
a. <package name> package:
b. package <package name>;
c. package:
d. <package name>;
Answer: Option B
Follow us for daily updates!
Q2. Which of the following source files cannot be included in a package?
Answer: D. data
Q3. Which of the following is/are used to access a public package?
Answer: a. Refer to the member by its fully qualified name
b. Import the package member
c. Import the member’s entire package
Q4. Which of the following statement(s) is/are false?
Answer: b. System.out.println() is a predefined java function.
Q5. Consider the program given below.
public class Main{
public static void main(String args[]) {
System.out.println (cos (2*PI));
}
}
What will be the output if the above program is executed?
Answer: a. It will give compile-time error
Q6. Which of the following is the minimum requirement for executing a Java program?
Answer: b. JRE
d. JRE without JDK
Q7. Which of the following is required for developing a Java program?
Answer: a. JDK
Q8. Which of the following statement(s) is/are correct?
Answer: b. Java byte code is generated by the compiler.
d. Java byte code is machine independent.
Q9. Which of the following is an advantage of methods?
Answer: a. Code re-usability
Q10. Consider the following programs:
public class Mainl{
public static void main(String args[]) {
int number = 10;
System.out.println (number+++++number);
}
}
public class Main2{
public static void main(String args[]) {
int number = 10;
System.out.println(++number+number++);
}
}
Choose correct statement about the output of this code segment.
Answer: C. Both Mainl and Main2 classes give the same output.
Java Programming Assignment 4 Answers
Q1.
import java.util.Scanner;
import java.io.*;
import static java.lang.System.*;
import java.util.LinkedList;
Q2.
java.util.Calendar current;
current = java.util.Calendar.getInstance();
year = current.get(current.YEAR);
Q3.
class Large
{
public void Print()
{
System.out.println("This is small");
}
}
class Medium extends Large
{
public void Print()
{
super.Print();
System.out.println("This is medium");
}
}
class Small extends Medium {
public void Print() {
super.Print();
System.out.println("This is large");
}
}
interface ExtraLarge{
static String extra = "This is extra-large";
void display();
}
Q4.
Second.super.show();
First.super.show();
Q5.
interface ShapeX
{
public String base = "This is Shape1";
public void display1();
}
interface ShapeY extends ShapeX
{
public String base = "This is Shape2";
public void display2();
}
class ShapeG implements ShapeY
{
public String base = "This is Shape3";
public void display1() {
System.out.println("Circle: " + ShapeX.base);
}
// Overriding method in ShapeY interface
public void display2() {
System.out.println("Circle: " + ShapeY.base);
}
}
Disclaimer: These answers are provided only for the purpose to help students to take references. This website does not claim any surety of 100% correct answers. So, this website urges you to complete your assignment yourself.
Also Available: