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

Programming in Java - - Unit 6 - Week 3 _

The document outlines the details of an assignment for a Programming in Java course, specifically for Week 3. It includes multiple-choice questions regarding Java programming concepts, such as static methods, final variables, and inheritance. The document also notes that the due date for submitting the assignment has passed and records that the user has not submitted it.

Uploaded by

kalidasji210
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Programming in Java - - Unit 6 - Week 3 _

The document outlines the details of an assignment for a Programming in Java course, specifically for Week 3. It includes multiple-choice questions regarding Java programming concepts, such as static methods, final variables, and inheritance. The document also notes that the due date for submitting the assignment has passed and records that the user has not submitted it.

Uploaded by

kalidasji210
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

13/11/2024, 15:25 Programming in Java - - Unit 6 - Week 3 :

(https://swayam.gov.in) (https://swayam.gov.in/nc_details/NPTEL)

vinamrasrivastava112@gmail.com 

NPTEL (https://swayam.gov.in/explorer?ncCode=NPTEL) » Programming in Java (course)

Course Week 03: Assignment 03


outline The due date for submitting this assignment has passed.
Due on 2024-08-14, 23:59 IST.
About As per our records you have not submitted this assignment.
NPTEL ()
1) What will be the output of the following program? 1 point

How does an
NPTEL
online class First {
course static void staticMethod() {
work? ()
System.out.println("Static Method");
Week 0 : () }
}
Week 1 : ()

Week 2 : () class MainClass {


public static void main(String[] args) {
Week 3 : ()
First first = null;
Lecture 11 : First.staticMethod();
Java Static
Scope Rule
}
(unit? }
unit=34&lesso
n=35)
a. Static Method
Lecture 12 : b. Throws a NullPointerException
Demonstration
-V (unit?
c. Compile-time error
unit=34&lesso d. Run time error
n=36)
No, the answer is incorrect.
Lecture 13 :
Inheritance

https://onlinecourses.nptel.ac.in/noc24_cs105/unit?unit=34&assessment=391 1/6
13/11/2024, 15:25 Programming in Java - - Unit 6 - Week 3 :

(unit? Score: 0
unit=34&lesso Accepted Answers:
n=37) a. Static Method

Lecture 14 : 2) What will be the output of the below program. 1 point


Demonstration
-VI (unit?
unit=34&lesso
class superDemoClass {
n=38)
final int a = 20;
Lecture 15 :
Information }
Hiding (unit?
unit=34&lesso
n=39) class subDemoClass extends superDemoClass {

Week 03 :
void subFunc() {
Programming a = 40;
Assignment 1
System.out.println("value of a = " + a);
(/noc24_cs105
/progassignme }
nt?name=376)
}
Week 03 :
Programming
Assignment 2 class demo {
(/noc24_cs105
public static void main(String[] args) {
/progassignme
nt?name=377) subDemoClass subc = new subDemoClass();

Week 03 :
subc.subFunc();
Programming }
Assignment 3
(/noc24_cs105
}
/progassignme
nt?name=378) a. value of a = 20

Week 03 : b. error: cannot assign a value to final variable ‘a’


Programming c. error: unknown variable 'a' in class subDemoClass
Assignment 4
d. value of a = 40
(/noc24_cs105
/progassignme No, the answer is incorrect.
nt?name=379) Score: 0
Accepted Answers:
Week 03 : b. error: cannot assign a value to final variable ‘a’
Programming
Assignment 5
3) All the variables of interface should be? 1 point
(/noc24_cs105
/progassignme
a. default and final
nt?name=380)
b. default and static
Quiz: Week
c. public, static and final
03:
Assignment d. protect, static and final
03
No, the answer is incorrect.
(assessment? Score: 0
name=391)
Accepted Answers:
Week 03 : c. public, static and final
Assignment

https://onlinecourses.nptel.ac.in/noc24_cs105/unit?unit=34&assessment=391 2/6
13/11/2024, 15:25 Programming in Java - - Unit 6 - Week 3 :

Solution (unit? 4) What will be the output of the below program. 1 point
unit=34&lesso
n=433)

class static_out {
Week 4 : ()
static int x;
Week 5 : () static int y;

Week 6 : ()
void add(int a, int b) {
Week 7 : () x = a + b;
y = x + b;
Week 8 : ()
}
Week 9 : () }

Week 10 : ()
public class static_use {
Week 11 : () public static void main(String args[]) {
static_out obj1 = new static_out();
Week 12 : ()
static_out obj2 = new static_out();
Books () int a = 2;
obj1.add(a, a + 1);
Text
Transcripts obj2.add(5, a);
() System.out.println(obj1.x + " " + obj2.y);
}
}

a. 7 7.4
b. 6 6.4
c. 7 9
d. 9 7

No, the answer is incorrect.


Score: 0
Accepted Answers:
c. 7 9

5) What will be the output of the following Java code? 1 point

class access {
public int x;
private int y;

void cal(int a, int b) {


x = a + 1;

https://onlinecourses.nptel.ac.in/noc24_cs105/unit?unit=34&assessment=391 3/6
13/11/2024, 15:25 Programming in Java - - Unit 6 - Week 3 :

y = b;
}

void print() {
System.out.println(" " + y);
}
}

public class access_specifier {


public static void main(String args[]) {
access obj = new access();
obj.cal(2, 3);
System.out.print(obj.x);
obj.print();
}
}

a. 2 3
b. 3 3
c. Runtime Error
d. Compilation Error

No, the answer is incorrect.


Score: 0
Accepted Answers:
b. 3 3

6) If a variable of primitive datatype in Java is declared as final, then 1 point

a. It cannot get inherited


b. Its value cannot be changed
c. It cannot be accessed in the subclass
d. All of the above

No, the answer is incorrect.


Score: 0
Accepted Answers:
b. Its value cannot be changed

7) Members which are not intended to be inherited are declared as 1 point

a. Public members
b. Protected members
c. Private members
d. Private or Protected members

No, the answer is incorrect.

https://onlinecourses.nptel.ac.in/noc24_cs105/unit?unit=34&assessment=391 4/6
13/11/2024, 15:25 Programming in Java - - Unit 6 - Week 3 :

Score: 0
Accepted Answers:
c. Private members

8) If a base class is inherited in protected access mode then which among the 1 point
following is true?

a. Public and Protected members of base class becomes protected members of derived
class
b. Only protected members become protected members of derived class
c. Private, Protected and Public all members of base, become private of derived class
d. Only private members of base, become private of derived class

No, the answer is incorrect.


Score: 0
Accepted Answers:
a. Public and Protected members of base class becomes protected members of derived class

9) Which type of inheritance leads to diamond problem? 1 point

a. Single level
b. Multi-level
c. Multiple
d. Hierarchical

No, the answer is incorrect.


Score: 0
Accepted Answers:
c. Multiple

10) What will be the output of the below program: 1 point

class superDemoClass {

final void func() {


int a = 20;
System.out.println("value of a = " + a);
}
}

class subDemoClass extends superDemoClass {


void func() {
int b = 60;
System.out.println("value of b = " + b);

}
}

class demo {

https://onlinecourses.nptel.ac.in/noc24_cs105/unit?unit=34&assessment=391 5/6
13/11/2024, 15:25 Programming in Java - - Unit 6 - Week 3 :

public static void main(String[] args) {


subDemoClass subc = new subDemoClass();
subc.func();

}
}

a. error: func() in subDemoClass cannot override func() in superDemoClass


b. value of b = 60
c. value of a = 20
d. None of the above

No, the answer is incorrect.


Score: 0
Accepted Answers:
a. error: func() in subDemoClass cannot override func() in superDemoClass

https://onlinecourses.nptel.ac.in/noc24_cs105/unit?unit=34&assessment=391 6/6

You might also like