Sign Up

Sign In

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Programming In Java Week 3 Assignment Answers 2022

NPTEL Programming in Java Assignment Answer

Are you looking for help in Programming In Java NPTEL Week 3 Assignment Answers? So, here in this article, we have provided Programming In Java week 3 Assignment Answer’s hint.

NPTEL Programming In Java Week 3 Assignment Answers

Q1. Which of this keyword can be used in a sub class to call the constructor of super class?

a. super
b. this
c. extent
d. extends

Answer: a. super

For instant notification of any updates, Join us on telegram.


Q2.

public class Question {
private static int i = 0;
private static int j = 0;
public static void main(String[] args) {
int i = 4;
int k = 5;
{
int j = 2;
System.out.println("i + j is "+i+j);
}
k = i + j;
System.out.println(k); 
System.out.println(j);
}
}

What is the output of the above program?

a. i+j is 42

4

0

b. i+j is 6

9

2

c. i+j is 42

9

2

d. i+j is 6

4

0

Answer: Option (A)


Q3.

public class Question
{ public static int x = 7; public static void main(String[] args) { Question a = new Question (); Question b = new Question (); a.x = 3; b.x = 2; System.out.println(a.x-b.x+Question.x); } }

What is the output of the above program?

a. 4

b. 10

c. 2

d. runtime error

Answer: c. 2


Q4. For each description on the left, find the best matching modifier on the right. You may use a choice more than once or not at all.

1. Hides the instance variable from code in other files. A. private

2. Hides the method from code in other files. B. public

c. Hides the subclass from code in other files. C. final

4. Exposes the API method to code in other files. D. static

5. Prevents the value of the instance variable from being Changed once initialized. E. none of the above

a. 1-A.2-A.3-C.4-D.5-E

b. 1-A.2-A.3-A.4-B.5-C

c. 1-C.2-B.3-A.4-A.5-D

d. None of Above

Answer: b. 1-A.2-A.3-A.4-B.5-C


Q5. All the variables of interface should be?

a. default and final

b. default and static

c. public, static and final

d. protect, static and final

Answer: c. public, static and final


Q6. Which of the following statement(s) is/are NOT true?

a. A final method cannot be overridden in a subclass.

b. The advantage of private static methods is that they can be reused later if you need to reinitialize the class variable.

c. Class methods cannot use this keyword as there is no instance for this to refer to.

d. A final method can be overridden in a subclass.

Answer: d. A final method can be overridden in a subclass.


Q7.

public class Test1{
Test1 () {
Test1 obj1 = new Test1();
}
public static void main(String [] args) { 
Test1 obj = new Test1(); 
System.out.println("Hello");
}
}

Which of the following statements is/are true?

a. Hello

b. There will be a compile-time error.

c. HelloHello.

d.  The program will give a runtime error.

Answer: d.  The program will give a runtime error.


Q8. Consider the composition of two classes as given below.

public class Question5{
public static void main(String args[]) {
String question= "Which course have you opted?"; System.out.print(Answer.submit(question));
}
}
class Answer{
static String answer = "Programming with Java";
static String submit(String question) {
return ("The answer to the question, "+question+" is "+answer); 
}
}

Which of the following option is true about the above program?

a. Error: String cannot be a method return type like void, int, char, etc.; as it is a class.

b. Error: Non-static variable answer’ cannot be referenced from a static context.

c. Output: The answer to the question. Which course have you opted? is Programming with Java

d. Error: Compilation error as variable ‘question’ is not static.

Answer: c. Output: The answer to the question. Which course have you opted? is Programming with Java


Q9. Disadvantage(s) of inheritance in Java programming is/are

a. Code readability

b. two classes (base and inherited class) get tightly coupled

c. Save development time and effort

d. Code reusability

Answer: b. two classes (base and inherited class) get tightly coupled


Q10. Which inheritance in Java programming is not supported?

a. Multiple inheritance using classes.

b. Multiple inheritance using interfaces.

c. Multilevel inheritance.

d. Single inheritance.

Answer: a. Multiple inheritance using classes.


TELEGRAM FOR NOTIFICATIONClick Here
Follow on Google News (in one click)Click Here

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:

NPTEL Programming In Java Week 4 Assignment Answers

NPTEL Programming In Java Week 2 Assignment Answers

Related Posts