Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

9/13/23, 12:19 AM Test your understanding - Packages (copy): Attempt review


 Dashboard / App Dev / Stage - 1 / Java Programming / Classes and Objects, Packages

Quiz review
Started on Wednesday, 13 September 2023, 12:02 AM
State Finished
Completed on Wednesday, 13 September 2023, 12:18 AM
Time taken 16 mins 40 secs
Marks 5.00/5.00
Grade 100.00 out of 100.00
Feedback Congratulations!!! You have passed by securing more than 80%

37547

37547

37547


https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=69972&cmid=1220 1/6
9/13/23, 12:19 AM Test your understanding - Packages (copy): Attempt review

Question 1
Correct

Mark 1.00 out of 1.00

Choose the correct option so that the code runs without any compilation errors

a. package test;

public class Main {


// Some code
}
import java.util.Scanner;

b. import java.util.Scanner;

public class Main {


// Some code
package test;

}
37547
c. package test; 

import java.util.Scanner;

public class Main {


// Some code

d. import java.util.Scanner;

public class Main {

}
// Some code
37547
package test;

Your answer is correct.

The correct answer is:


package test;

import java.util.Scanner;
public class Main {

}
// Some code
37547


https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=69972&cmid=1220 2/6
9/13/23, 12:19 AM Test your understanding - Packages (copy): Attempt review

Question 2
Correct

Mark 1.00 out of 1.00

Given the below code :


____________________________
public class AreaCalculator {
public double calculateArea(double radius) {

double area = PI * radius * radius; //Instead of Math.PI


return area;
}
}
Fill in the blank by choosing the correct import statement to use the static variable PI.

37547
a. import static java.lang.Math.PI; 

b. import java.lang.Math.PI;

c. import static java.lang.Math;

Your answer is correct.

The correct answer is:


import static java.lang.Math.PI;

37547

37547


https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=69972&cmid=1220 3/6
9/13/23, 12:19 AM Test your understanding - Packages (copy): Attempt review

Question 3
Correct

Mark 1.00 out of 1.00

Given the class Book and Library in two different packages :


1. package model;
2. public class Book {
3. private static void countBook { }

4. }

1. package util;
2. public class Library {
3. public static void main(String[] args) {
4. // insert code here

37547
5. }

6. }
What is required at line 4 in class Library to use the countBook method of Book class?

Select one:
a. util.Library.countBook();

b. countBook();

c. model.Book.countBook();

d. Book.countBook();

e. Library class cannot use the countBook method in Book class.

37547
countBook() cannot be invoked since the method is declared private.
The correct answer is: Library class cannot use the countBook method in Book class.

37547


https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=69972&cmid=1220 4/6
9/13/23, 12:19 AM Test your understanding - Packages (copy): Attempt review

Question 4
Correct

Mark 1.00 out of 1.00

Assume class Calculator in package p1 and CalculatorService class in package p2 as shown below.
package p1;
public class Calculator {
__________ static void calculate(){

//some code here


}
}
package p2;
import p1.Calculator;
public class CalculatorService {

37547
public void display(){

Calculator.calculate();

}
}

What can be the valid access specifier for the calculate method in Calculator class so that it can be accessed from CalculatorService
class?

Select one:
a. Any access specifier except private

b. default

37547
c. private

d. protected

e. public

If a method defined within a class in one package has to be invoked from outside, then that method has to be declared public.

The correct answer is: public

37547


https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=69972&cmid=1220 5/6
9/13/23, 12:19 AM Test your understanding - Packages (copy): Attempt review

Question 5
Correct

Mark 1.00 out of 1.00

Given the class Book in packages p1 and class Main in package p2. In main to create an object of Book, which of the following are
valid.

Select one:
a. p1.Book bookObj=new p1.Book();

b. p1.Book bookObj=new Book();

c. Book bookObj=new Book();

Since the Book class is present within p1 package, it has to be accessed as "p1.Book", everytime, from package p2.
The correct answer is: p1.Book bookObj=new p1.Book();

37547
◄ Packages

Jump to...

Classes and Objects, Packages - Demo ►

37547

37547


https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=69972&cmid=1220 6/6

You might also like