NPTEL Programming In Java Assignment 4 Answers 2023:- All the Answers provided here to help the students as a reference, You must submit your assignment at your own knowledge
What is Programming In Java?
With the growth of Information and Communication Technology, there is a need to develop large and complex software. Further, those software should be platform independent, Internet enabled, easy to modify, secure, and robust. To meet this requirement object-oriented paradigm has been developed and based on this paradigm the Java programming language emerges as the best programming environment. Now, Java programming language is being used for mobile programming, Internet programming, and many other applications compatible to distributed systems. This course aims to cover the essential topics of Java programming so that the participants can improve their skills to cope with the current demand of IT industries and solve many problems in their own filed of studies.
CRITERIA TO GET A CERTIFICATE
Average assignment score = 25% of the average of best 8 assignments out of the total 12 assignments given in the course.
Exam score = 75% of the proctored certification exam score out of 100
Final score = Average assignment score + Exam score
YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF THE AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.
Below you can find the answers for NPTEL Programming In Java Assignment 2
ALSO READ :-
NPTEL Registration Steps [July – Dec 2022]
NPTEL Exam Pattern Tips & Top Tricks [2022]
NPTEL Exam Result 2022 | NPTEL Swayam Result Download
NPTEL Programming In Java Week 4 Quiz Assignment Answers 2023
Q1. Which of the following is the correct statement for creating a package?
a. package;
b. package «package name>;
c. package:
d. «package name>;
Answer:- b
2. How Java Runtime Environment (JRE) knows where to look for a package that you create?
a. It searches in the current directory.
b. It searches in the location set in the CLASSPATH environment variable.
c. A user can set the path during runtime using the -classpath option.
d. Using the -path option, a user can set the path.
Answer:- a, b, c
3. Which of the following statements) is/are false?
a. Java packages are hierarchical.
b. system.out.println () is a predefined java function.
c. Java can have a nested class structure.
d. The Java static kevword is a non-access modifier.
Answer:- For Answer Click Here
4. Which of the following is/are NOT correct regarding packages in Java?
a. Java supports both pre-defined and user-defined packages.
b. Packages are used to organize a set of related classes and interfaces.
c. Pre-defined packages help to develop programs easily by providing thousands of classes.
d. Packages are used to organize only a set of related classes and not interfaces.
Answer:-
5. 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?
a. It will give compile-time error
b. It will give run-time ertor
c. 1.0
d. 3.14
Answer:-
6. Which of the following is the minimum requirement for executing a Java program?
a. JDK
b. RE
c. JDK without JRE
d. JRE without JDK
Answer:- For Answer Click Here
7. Which of the following is required for developing a Java program?
a. DK
b. IRE
c. JDK without JRE
d. JRE without JDK
Answer:-
8. Which of the following is/are valid declaration(s) of an interface?
a. public interface Question (
void method (int value) {
System.out.println ("Nptel");
]
b.public interface Question (
void method (int value);
)
c. public interface Question (
)
d. public interface Question (
default void method (int value) |
System.out.println ("Nptel");
Answer:- For Answer Click Here
9. Which of the following statements) is/are NOT true?
a. The default package in the Java language is java lang.
b. String is a final class and it is present in java.lang package.
c. Runnable is a class present in java.lang package.
d. Thread is a class present in java.lang package.
Answer:-
10. Which of the following statements) is/are true?
a. With the import statement, generally import only a single package member or an entire
package.
b. To import all the types contained in a particular package, use the import statement with
the asterisk () wildcard character. import package.;
C. import package.A: it used to match a subset of the classes in a package starts with “A”
d. import package.A: it generates compilation error.
Answer:- For Answer Click Here
NPTEL Programming In Java Week 4 Programming Assignment Solutions 2023
Q1. Complete the code segment to execute the following program successfully. You should import the correct package(s) and/or class(s) to complete the code.
Solution:-
// Import the required package(s) and/or class(es) import java.util.Scanner; import static java.lang.System.*; // main class Question is created public class Question41{ public static void main(String[] args) { // Scanner object is created Scanner scanner = new Scanner(System.in); // Read String input using scanner class String courseName = scanner.nextLine(); // Print the scanned String out.println("Course: " + courseName); } }
Q2. Complete the code segment to print the current year. Your code should compile successfully.
Note: In this program, you are not allowed to use any import statement. Use should use predefined class Calendar defined in java.util package.
Solution:-
Answer:- For Answer Click Here
Q3. The program in this assignment is attempted to print the following output:
—————–OUTPUT——————-
This is large
This is medium
This is small
This is extra-large
———————————————–
However, the code is intentionally injected with some bugs. Debug the code to execute the program successfully.
Solution:-
Answer:- For Answer Click Here
Q4. Complete the code segment to call the default method in the interface First and Second.
Solution:-
Answer:- For Answer Click Here
Q5. Modify the code segment to print the following output.
—————–OUTPUT——————-
Circle: This is Shape1
Circle: This is Shape2
————————————————-
Solution:-
Answer:- For Answer Click Here
NPTEL Programming In Java Assignment 4 Answers July 2022
1. Which of these is a mechanism for naming and visibility control ofa class and its content?
a. Objects.
b. Intertaces.
c. Packages.
d. Both a and b.
Answer:- c
2. Which of the following is false statement about packages in java?
a. Packages are used to organize a set of related classes and interfaces.
b. Packages are used for preventing naming conflicts.
c. Packages provide code reusabilty.
d. Packages cannot be considered as data encapsulation.
Answer:- d
Answers will be Uploaded Shortly and it will be Notified on Telegram, So JOIN NOW
3. Which of the following is/are interface(s) of java.awt package?
a. CardLayout
b. Checkbox
c. Choice
d. MeuContainer
Answer:- d
4. Which of the following statement(s) is/are false?
a. The default package in the Java language is java.lang.
b. String is a final class and it is present in java.lang package.
c. Cloneable is a class present in java.lang package.
d. Thread is a class present in java.lang package.
Answer:- c
5. Consider the program given below.
What will be the output if the above program is executed?
import static java.lang.Math.'
public class Main {
public static void main (String args[ ] ) {
System.out.println (cos (2*PI) ) ;
}
}
- a. It will give compile-time eror
- b. It will give run-time error
- c. 1.0
- d. 3.14
Answer:- c
6. Which of the following packages is used to includes utility classes like Calendar, Collections, Date?
a. java.lang
b. java.util
c. java.net
d. java.awt
Answer:- b
👇For Week 05 Assignment Answers👇
7. Which of the following statement(s) is/are false?
a. Comparable interface is present in java.lang package
b. Iterator interface is present in java.util package.
c. Compare() is a method used in Comparable interface.
d. Serializable interface is present in java.io package.
Answer:- c
8. Image size is too small for OCR Engine 2. Please use Engine 1.
a. public interface Question { void method(int value){ System.out.println("Nptel"); }
b. public interface Question { void method(int value){
c. public interface Question {
d. public interface Question { default void method(int value){ System.out.println("Nptel");
Answer:- b, c, d
9. Which of the following is false statement about interface in java?
a. An interface can extend other interfaces.
b. The interface body can contain abstract methods, default methods, and static methods.
c. All constant values defined in an interface are implicitly public, static, and final.
d. A static method in an interface are implicitly private.
Answer:- For Answer Click Here
10. Which of these access specifier(s) can be used for an interface?
a. Public
b. Protected
c. Private
d. Both b and c
Answer:- a
NPTEL Programming In Java Week 4 Programming Assignment Answers July 2022
Q1. Complete the code segment to execute the following program successfully. You should import the correct package(s) and/or class(s) to complete the code.
import static java.lang.System.*;
import java.util.Scanner;
Q2. Complete the code segment to print the current year. Your code should compile successfully.
java.util.Calendar current_date;
current_date = java.util.Calendar.getInstance();
year = current_date.get(current_date.YEAR);
Q3. The program in this assignment is attempted to print the following output:
interface ExtraLarge_interface
{
static String ext = "This is extra-large";
void display();
}
class Large
{
public void Print()
{
System.out.println("This is large");
}
}
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 small");
}
}
class Question43 implements ExtraLarge_interface
{
public static void main(String[] args)
{
Small s1 = new Small();
s1.Print();
Question43 q1 = new Question43();
q1.display();
}
public void display()
{
System.out.print(ext);
}
}
Q4. Complete the code segment to call the default method in the interface First and Second.
First.super.show();
Second.super.show();
Q5. Modify the code segment to print the following output.
interface ShapeX
{
public String b = "This is Shape1";
public void display1();
}
interface ShapeY extends ShapeX
{
public String b = "This is Shape2";
public void display2();
}
class ShapeG implements ShapeY
{
public String b = "This is Shape3";
public void display1() {
System.out.println("Circle: " + ShapeX.b);
}
public void display2()
{
System.out.print("Circle: " + ShapeY.b);
}
}
For More NPTEL Answers:- CLICK HERE
Join Our Telegram:- CLICK HERE
NPTEL Programming In Java Assignment 4 Answers Jan 2022
Q1. Complete the code segment to execute the following program successfully. You should import the correct package(s) and/or class(s) to complete the code.
Code:-
// Import the required package(s) and/or class(es)// Import the required package(s) and/or class(es)
import java.io.*;
import java.util.*;
import static java.lang.System.*;
👇FOR NEXT WEEK ASSIGNMENT ANSWERS👇
Q2. Complete the code segment to print the current year. Your code should compile successfully.
Code:-
// Create an object of Calendar class.
java.util.Calendar current ;
// Use getInstance() method to initialize the Calendar object.
current = java.util.Calendar.getInstance();
// Initialize the int variable year with the current year
year = current.get(current.YEAR);
Q3. The program in this assignment is attempted to print the following output:
Code:-
interface ExtraLarge{
String extra = "This is extra-large";
void display();
}
class Large {
public void Print() {
System.out.println("This is large");
}
}
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 small");
}
}
class Question43 implements ExtraLarge{
public static void main(String[] args) {
Small s = new Small();
s.Print();
Question43 q = new Question43();
q.display();
}
public void display(){
System.out.println(extra);
}
}
Q4. Complete the code segment to call the default method in the interface First and Second.
Code:-
// Call show() of First interface.
First.super.show();
// Call show() of Second interface.
Second.super.show();
Q5. Modify the code segment to print the following output.
Code:-
// Interface ShapeX is created
interface ShapeX {
public String base = "This is Shape1";
public void display1();
}
// Interface ShapeY is created which extends ShapeX
interface ShapeY extends ShapeX {
public String base = "This is Shape2";
public void display2();
}
// Class ShapeG is created which implements ShapeY
class ShapeG implements ShapeY {
public String base = "This is Shape3";
//Overriding method in ShapeX interface
public void display1() {
System.out.println("Circle: " + ShapeX.base);
}
// Override method in ShapeY interface
public void display2(){
System.out.println("Circle: " + ShapeY.base);}
}
👇FOR NEXT WEEK ASSIGNMENT ANSWERS👇
Disclaimer:- We do not claim 100% surety of solutions, these solutions are based on our sole expertise, and by using posting these answers we are simply looking to help students as a reference, so we urge do your assignment on your own.
For More NPTEL Answers:- CLICK HERE
Join Our Telegram:- CLICK HERE
Programming In Java Assignment 4 Answers 2022:- All the Answers provided here to help the students as a reference, You must submit your assignment at your own knowledge
If you found this article Interesting and helpful, don’t forget to share it with your friends to get this information.Categories