MCQs / Computer Science / Lab: Student Information App Using Resources

Lab: Student Information App Using Resources MCQs — Computer Science

16 multiple-choice questions on Lab: Student Information App Using Resources from Computer Science, each with the correct answer and, where available, a teacher's explanation. Read through them to revise the chapter, then practise the same questions one by one to test yourself.

1. In XML, a string resource named nameali is referenced as:

  1. string:nameali
  2. @string/nameali
  3. string/nameali
  4. R.string.nameali

Answer: B) @string/nameali

Explanation: XML uses @string/..., while code uses R.string....

Discuss this question

2. Which call changes an ImageView's picture to another drawable at run time?

  1. img.text = R.drawable.x
  2. setContentView(R.drawable.x)
  3. img.loadUrl(R.drawable.x)
  4. img.setImageResource(R.drawable.studentsara)

Answer: D) img.setImageResource(R.drawable.studentsara)

Explanation: setImageResource sets a drawable resource by ID.

Discuss this question

3. The folder values-ur contains:

  1. Images for Urdu
  2. Colours for dark mode
  3. Strings used when the device language is Urdu
  4. Layouts for tablets

Answer: C) Strings used when the device language is Urdu

Explanation: values-ur is a locale qualifier for Urdu resources.

Discuss this question

4. Which folder should hold the student photos?

  1. assets/strings
  2. res/drawable
  3. res/values
  4. res/layout

Answer: B) res/drawable

Explanation: Images used by the UI are drawable resources.

Discuss this question

5. Text sizes should be specified in:

  1. pt
  2. sp
  3. dp
  4. px

Answer: B) sp

Explanation: sp scales with the user's font-size preference.

Discuss this question

6. The attribute that describes an ImageView for screen readers is:

  1. android:hint
  2. android:label
  3. android:alt
  4. android:contentDescription

Answer: D) android:contentDescription

Explanation: contentDescription provides accessibility text.

Discuss this question

7. Which scaleType crops the image to fill the ImageView while keeping its ratio?

  1. fitXY
  2. centerCrop
  3. matrix
  4. center

Answer: B) centerCrop

Explanation: centerCrop scales uniformly and crops the overflow.

Discuss this question

8. If a string is missing in values-ur/strings.xml, Android uses:

  1. The default value from values/strings.xml
  2. An empty string
  3. A crash
  4. The English keyboard

Answer: A) The default value from values/strings.xml

Explanation: Resources fall back to the default (unqualified) folder.

Discuss this question

9. dp stands for:

  1. Density-independent pixels
  2. Dots per point
  3. Display pixels
  4. Device points

Answer: A) Density-independent pixels

Explanation: dp keeps sizes physically similar on screens of different densities.

Discuss this question

10. Which is a VALID name for a drawable resource file?

  1. 1student.jpg
  2. studentali.jpg
  3. Student-Ali.JPG
  4. Student Ali.jpg

Answer: B) studentali.jpg

Explanation: Resource names may contain only lowercase letters, digits and underscores, starting with a letter.

Discuss this question

11. In the lab, index = (index + 1) % photos.size is used to:

  1. Sort names
  2. Delete photos
  3. Count clicks only
  4. Cycle back to the first student after the last one

Answer: D) Cycle back to the first student after the last one

Explanation: The modulo wraps the index around to 0.

Discuss this question

12. Which method returns the text of a string resource in an activity?

  1. setText(R.drawable.name)
  2. getString(R.string.name)
  3. findViewById()
  4. getDrawable(R.string.name)

Answer: B) getString(R.string.name)

Explanation: getString(resId) returns the string value.

Discuss this question

13. Resource IDs like R.drawable.studentali are of which type?

  1. String
  2. int
  3. File
  4. Bitmap

Answer: B) int

Explanation: Resource IDs are integer constants in the generated R class.

Discuss this question

14. In a vertical LinearLayout, child views are arranged:

  1. Side by side
  2. In a grid
  3. One below another
  4. On top of each other

Answer: C) One below another

Explanation: orientation="vertical" stacks children from top to bottom.

Discuss this question

15. Which attribute sets the image shown by an ImageView in XML?

  1. android:text
  2. android:drawablePath
  3. android:image
  4. android:src

Answer: D) android:src

Explanation: android:src points to a drawable resource.

Discuss this question

16. View Binding replaces the need for:

  1. AndroidManifest.xml
  2. strings.xml
  3. findViewById()
  4. setContentView()

Answer: C) findViewById()

Explanation: View Binding generates a class with direct references to views.

Discuss this question

Practise Lab: Student Information App Using Resources MCQs

More Computer Science chapters