This set of MCQ(multiple choice questions) focuses on the Programming in Java NPTEL 2023 Week 3 Quiz Solutions.
Course layout (Answers Link)
Answers COMING SOON! Kindly Wait!
Week 1: Overview of Object-Oriented Programming and Java
Programming Assignment
Week 2: Java Programming Elements
Programming Assignment
Week 3: Input-Output Handling in Java
Programming Assignment
Week 4: Encapsulation
Programming Assignment
Week 5: Inheritance
Programming Assignment
Week 6: Exception Handling
Programming Assignment
Week 7: Multithreaded Programming
Programming Assignment
Week 8: Java Applets and Servlets
Programming Assignment
Week 9: Java Swing and Abstract Windowing Toolkit
Week 10: Networking with Java
Week 11: Java Object Database Connectivity
Week 12: Interface and Packages for Software Development
NOTE: You can check your answer immediately by clicking show answer button. Programming in Java NPTEL 2023 Week 3 Quiz Solutions” contains 10 questions.
Now, start attempting the quiz.
Programming in Java NPTEL 2022 Week 1 Quiz Solutions
Q1. In which of the following scenario(s), the static block is used in Java?
a) To create static variables
b) To initialize instance variables
c) To initialize static variables
d) To create new objects
Answer: c) To initialize static variables
Q2. Consider the following piece of code.
Fill in the blank with the appropriate keyword(s) from the list given below so that the program compiles successfully.
a) public void
b) private void
c) public static void
d) private static void
Answer: c), d)
Q3. What is the output of the above code?
a) A’s display method
B’s display method
b) A’s display method
A’s dispaly method
c) B’s display method
B’s display method
d) B’s display method
A’s display method
Answer: c)
Q4. Which of the following statement(s) is/are false?
a) You can write a new instance method in the subclass with the same signature as the one in the superclass, thus overriding it
b) You can write a new static method in the subclass with the same signature as the one in the superclass, thus hiding it
c) A subclass inherits all of its parent’s public and protected memebers, no matter what package the subclass is in
d) You cannot declare new methods in the subclass that are not in the superclass
Answer: d)
Q5. Which of the following statement(s) is/are true?
a) You will get a compile-time error if you attempt to change an instance method in the superclass to a static method in the subclass
b) You can prevent a class from being subclassed by using the final keyword in the class’s declaration
c) An abstract class can be instantiated
d) Common behaviour can be defined in a superclass and inherited into a subclass using the extends keyword
Answer: a), b), d)
Q6. What is the output of the above program?
a) prgam
b) program
c) gramm
d) ing in
Answer: a) prgam
Q7. Which of the following is the output of the above program?
a) 10
100
b) 10
20
c) 100
10
d) 10
19
Answer: a)
Q8. If the program is executed, then what will be the output from the execution?
a) 1700
b) 1300
c) 0
d) 2600
Answer: a) 1700
Q9. Which of the following statement(s) is/are true?
a) Hiding internal data from the outside world and accessing it only through publicly exposed methods is known as data encapsulation
b) Static methods in interfaces are never inherited
c) The term “class variable” is another name for a non-static field
d) A local variable stroes a temporary state; it is declared inside a method
Answer: a), c), d)
Q10. All classes in java are inherited from which class?
a) java.lang.class
b) java.class.inherited
c) java.class.object
d) java.lang.object
Answer: d)
Programming in Java NPTEL 2023 Week 3 Quiz Solutions
Q1. Which of the following statement(s) is/are correct about the constructor?
a) Constructors cannot be synchronized in Java
b) Java does not provide a default copy constructor
c) A constructor cannot be overloaded
d) “this” or “super” can be used in a constructor
Answer: a), b), d)
Q2. Which of the following statement(s) is/are true?
a) You can write a new instance method in the subclass with the same signature as the one in the superclass, thus overriding it.
b) You can write a new static method in the subclass with the same signature as the one in the superclass, thus hidiing it.
c) A subclass inherits all of its parent’s public and protected members, no matter what package the subclass is in.
d) You cannot declare new methods in the subclass that are not in the superclass.
Answer: a), b), c)
Q3. Fill in the blank with the appropriate keyword(s) from the list given below so that the program compiles successfully.
a) abstract
b) final
c) default
d) public
Answer: b), d)
Q4. How many instances of abstract class can be created?
a) 0
b) 1
c) 2
d) Multiple
Answer: a)
Q5. Structure a Java class such that only methods within the class can access its instance variables is referred to as ________.
a) Object orientation
b) inheritance
c) platform independence
d) encapsulation
Answer: d)
Q6. Which of the following statement(s) is/are 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 refer to
d) A final method can be overridden in a subclass
Answer: a), b), c)
Q7. Which of the following is the output of the above program?
a) Java
b) There will be a compile-time error
c) JavaJava
d) The program will give a runtime error
Answer: b)
Q8. What is the output of the above program?
a) java
b) ring
c) r min
d) gram
Answer: b)
Q9. Which of the following statement(s) is/are False?
a) Hiding internal data from the outside world and accessing it only through publicly exposed methods is known as data encapsulation
b) Common behavior can be defined in a superclass and inherited into a subclass using the extends keyword
c) The term “class variable” is another name for a non-static field
d) A local variable stores a temporary state; it is declared inside a method.
Answer: c)
Q10. Which of the following statement(s) is/are true?
a) Static methods in interfaces are never inherited
b) You will get a compile-time error if you attempt to change an instance method in the superclass to a static method in the subclass
c) You can prevent a class from being subclassed by using the final keyword in the class’s declaration
d) An abstract class can only be subclassed; it cannot be instantiated
Answer: a), b), c), d)
Programming in Java NPTEL 2022 Week 3 Quiz Solutions
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
Q2. 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: a)
Q3. 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.
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. 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. 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.
Previous Course – Week 3 Quiz Solutions
Q1. Consider the following piece of code in Java.
class A {
public int i;
protected int j;
}
class B extends A
{
void display()
{
super.j = super.j-super.i;
System.out.println(super.i + " " + super.j);
}
}
public class inheritance
{
public static void main(String args[])
{
B obj = new B();
obj.i=3;
obj.j=6;
obj.display();
}
}
What is the output of the above program?
a) 2 3
b) 3 3
c) Runtime Error
d) Compilation Error
Answer: b) 3 3
Q2. Consider the following piece of code in Java.
public class Question
{
public static int x = 7;
public static void main(String[] args) {
Question a = new Question ();
Question b = new Question ();
a.x = 2;
b.x = 2;
System.out.println(a.x+b.x+Question.x);
}
}
What is the output of the above program?
a) 6
b) 10
c) 21
d) error
Answer: a) 6
Q3. If a class inheriting an abstract class does not define all of its functions then it will be known as?
a) Default
b) Abstract
c) A simple class
d) Static class
Answer: b) Abstract
Q4. Which among the following best describes polymorphism?
a) It is the ability for many messages/data to be processed in one way
b) It is the ability for a message/data to be processed in only 1 form
c) It is the ability for a message/data to be processed in more than one form
d) It is the ability for undefined message/data to be processed in at least one way
Answer: c) It is the ability for a message/data to be processed in more than one form
Q5. Consider the following piece of code in Java
class Men
{
int walkingDistance(int weight)
{
System.out.println(10);
return 10;
}
}
class WildMen extends Men
{
void walkingDistance(int weight)
{
System.out.println("20");
}
}
public class MethodOverriding3
{
public static void main(String[] args)
{
WildMen wc = new WildMen();
wc.walkingDistance(30);
}
}
What is the output of the above program?
a) 30
b) 20
c) Compile error
d) Runtime error
Answer: c) Compile error
Q6. All the variables of the 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
Q7. Disadvantage(s) of inheritance in Java programming is/are
a) Code readability
b) two classes (base and inherited class) get tightly coupled
c) Code maintainability
d) Code reusability
Answer: b) two classes (base and inherited class) get tightly coupled
Q8. When does method overloading is determined?
a) At run time
b) At coding time
c) At compile time
d) At execution time
Answer: c) At compile time
Q9.
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) Output: Hello
b) Program will compile successfully
c) There will be a compile-time error
d) The program will give a runtime error
Answer: b), d)
Q10. Which of the following statement(s) is/are true?
a) Hiding internal data from the outside world, and accessing it only through publicly exposed methods is known as data encapsulation
b) Common behavior can be defined in a superclass and inherited into a subclass using the extends keyword
c) The term “class variable” is another name for static field
d) A local variable stores temporary state; it is declared inside a method
Answer: a), b), c), d)
>> Next- Programming in Java Week 2 Assignment Solutions
>> Next- Programming in Java Week 4 Assignment Solutions
DISCLAIMER: Use these answers only for the reference purpose. Quizermania doesn't claim these answers to be 100% correct. So, make sure you submit your assignments on the basis of your knowledge.
For discussion about any question, join the below comment section. And get the solution of your query. Also, try to share your thoughts about the topics covered in this particular quiz.
Please share assignment 3 programming answers