0% found this document useful (0 votes)
578 views27 pages

What Is A Program

A program is a series of instructions that a computer executes to accomplish some action. The fun keyword is used to define functions in Kotlin. To create a Kotlin program that prints text requires a main() function, curly braces around the instructions, and a call to print() or println(). This sample Kotlin code will print two lines of text. Comments are useful for explaining code to yourself and others. Class inheritance allows code reuse and makes programs easier to maintain. Abstract classes cannot be instantiated and need to be extended by subclasses.

Uploaded by

Ahmed Hamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
578 views27 pages

What Is A Program

A program is a series of instructions that a computer executes to accomplish some action. The fun keyword is used to define functions in Kotlin. To create a Kotlin program that prints text requires a main() function, curly braces around the instructions, and a call to print() or println(). This sample Kotlin code will print two lines of text. Comments are useful for explaining code to yourself and others. Class inheritance allows code reuse and makes programs easier to maintain. Abstract classes cannot be instantiated and need to be extended by subclasses.

Uploaded by

Ahmed Hamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

1. What is a program?

01) A specific task


02) A tool that helps you write Kotlin code
03) A series of instructions that a computer system
executes to accomplish some action
04) A defined set of instructions that tells your computer
to print “Happy Birthday!”

2. Which keyword do you use to define a function in


Kotlin?
01) fun
02) func
03) function
04) newFunction
05) main

3.Which of the following do you need to create a


Kotlin program that prints a line of text?
Choose as many answers as you see fit.
01) comment describing what your program does
02) a main() function
03) curly braces {} around the instructions to the system
04) a call to print() or println()
05) a repeat() statement

3. What do you expect this Kotlin code to do?


fun main(args: Array<String>) {
println("Hello, world!")
println("It's a sunny and warm day!")
}

01) Print one line of text


02) Print two lines of text
03) Print three lines of text
04) Print two lines of text separated by a blank line

4. How would you modify this main() function so that it


prints a 6-layer cake for someone's 4th birthday?
fun main() {
val age = 24
val layers = 5
printCakeCandles(age)
printCakeTop(age)
printCakeBottom(age, layers)
}

01) Set val age to 6, set val layers to 4


02) Set val age to "4", set val layers to "6"
03) Set val age to 4, set val layers to 6
04) Leave the code as-is

5. Which of these options correctly calls the function,


below, and passes it valid input arguments?
fun createMessage(name: String, location: String, age:
Int) {
println("My name is ${name}. I am from ${location},
and I am ${age} years old.")
}

01) createMessage("Amy", "Australia", 20)


02) createMessage("Evan", England, 9)
03) createmessage("Tom", "Thailand", “40”)
04) createMessage(Heather, “Haiti”, 7)
6.What does IDE stand for?
01) Integrated Development Environment
02) Independent Design Environment
03) Ideal Developer Environment
04) Intelligent Design Environment

7.Which of the following are advantages of using


Android Studio?
Choose as many answers as you see fit.
01) It can help prevent typos and other mistakes in your
code.
02) It comes with a virtual device called an emulator that
can run your app.
03) It can show you a real-time preview of how your app
will look on-screen while you code.
04) It can automatically translate your app into other
languages.

8.What does “Minimum SDK” refer to in an Android


Studio project?
01) The minimum amount of storage that your app
requires for download
02) The minimum number of devices that your app can
access
03) The minimum download speed that your app requires
04) The minimum version of Android that your app can
run on

9.What is the purpose of using a virtual device, or


emulator, in Android Studio?
01) To show a variety of error messages to users
02) To experiment with app code safely
03) To test your app on a device without having that
physical device
04) To see what your app looks like in a web browser

10.In Android Studio, what is a project template good


for?
Choose as many answers as you see fit.
01) It causes Android Studio to download files faster.
02) It makes getting started on building a new app faster.
03) It provides a structure that follows best practices.
04) It is the only way to build apps that can be previewed
in Android Studio.
05) It makes building a new app less error-prone by pre-
populating the project with some app code.

11.How do you create a new project in Android


Studio?
A. Log out of Android Studio, and navigate to your
project folder to find instructions.
B. If you have a project already open, select File > New >
New Project from the Android Studio menu.
C. In the “Welcome to Android Studio” window, click
“Start a new Android Studio project.”
D. Create a new file on your computer, and title it “New
Android Studio Project."
- Both B and C are ways to create a new project in
Android Studio.
- None of the above
12.Which of the following elements is considered a
View in an Android app?
01) An image
02) A clickable button
03) Text on the screen
04) All of the above
05) None of the above

13.What is the main purpose of a ViewGroup?


01) It groups together the most common views that
developers use in Android apps.
02) It serves as a container for View objects, and is
responsible for arranging the View objects within it.
03) It is required to make a view interactive as a way to
group TextViews on a screen.
04) It is required to set colors and background images

14.The ViewGroup that helps you arrange the views


inside of it in a flexible way is called a ___.
01) ImageView
02) ConstraintLayout
03) TextView

15.Which of the following are Attributes in Android?


Choose as many answers as you see fit.
01) text
02) textSize
03) textUse
04) textColor
05) textContent

16.Which of the following is an example of a


“constraint” that could be applied to a view in a
ConstraintLayout ViewGroup in the Layout Editor?
Choose as many answers as you see fit.
01) A view that must always be a minimum distance away
from the edge of its container
02) A view that must always be free of warning triangles
03) A view that must always be to the right of another
view
04) A view that must always be the topmost view inside a
container
05) A view that must always include a contentDescription
attribute

17.What is the purpose of the activity_main.xml file in


the project you created?
01) It provides the theme settings for your app.
02) It lets your app users create their own custom views
of the app.
03) It stores all the images your app will use.
04) It describes the layout of view groups and views for a
screen.

18. Why should you use string resources instead of


hard-coded strings in your apps?
Choose as many answers as you see fit.
.
01) It makes your app easier to translate.
02) It allows you to use longer strings in your app.
03) It allows you to apply special color attributes to your
string.
04) It allows you to reuse the same string in multiple
places in your program.

19.Which of the following is an example of a class?


Choose as many answers as you see fit.
01) A Car class that has a make and model, and that can
be driven
02) A Flower class that has a scent
03) A Puppy class that has breed, weight and age, and that
can barkA ShoppingCart class that has a cart size and cart
value, and that can hold items
04) A Song class that has lyrics
05) None of these are examples of a class.

20.Which of the following is a difference between a


class and an instance?
Choose as many answers as you see fit.
01) You can think of a class as a blueprint and an instance
as the actual “thing".
02) A class is like architectural plans for a bridge, and the
Golden Gate bridge an instance of those plans.
03) A class is for defining categories of "things", while
instances are for defining their properties.
04) You can create multiple instances from a class, but
you can't create classes from instances.

21.True or false? Every MainActivity class in Android


must have a main() function.
01) True
02) False

22.Which of the following is NOT a way for creating a


comment in Kotlin?
Choose as many answers as you see fit.
01) Add // at the beginning of or inside a line and
anything after that // is considered a comment.
02) Put /* or /** to start a block comment, and end it with
*/.
03) Use // to turn the rest of a function into a comment.
04) Use /* to start a comment that is one line long.

23.Which of the following statements about a


conditional statement is true?
Choose as many answers as you see fit.
01) A conditional statement is a way for you to set up a
condition and ensure that code following it is only
executed if that condition is met.
02) A conditional statement does not require any
keywords.
03) A conditional statement should only be used with
integers as input.
04) A conditional statement can be used within functions
to return output based on conditions defined in that
function.

24.What is a good reason for you to add comments to


your code?
01) To explain to yourself or others why the code is
written a certain way.
02) To structure code, like chapter headings in books.
03) To point out some part of the code that is very
important.
04) To explain to other developers how to use your code
for their own programs.
05) All of the above
06) None of the above

25.Which of the following are Kotlin data types?


Choose as many answers as you see fit.
01) IntRange
02) Num
03) Int
04) Boolean (true or false)

26.Which of the following are valid keywords used in


conditional statements in Kotlin?
Choose as many answers as you see fit.
01) if, else
02) if, then, stop
03) when

27.Which of the following is true about class


inheritance?
01) Class inheritance lets you reuse code and makes your
program easier to maintain.
02) Properties and functions of the parent class(es) are
available to the child class.
03) You can define additional properties and functions
that are specific to subclasses.
04) You can override parent class members in subclasses.
05) All of the above

28.Which of the following are true about abstract


classes?
Choose as many answers as you see fit.
01) They can be extended by subclasses and
implementations can be provided for abstract members of
the class.
02) They have an implementation for all of their
properties and functions.
03) They may have abstract properties or abstract
functions.
04) They can be instantiated.
05) They are not fully implemented and cannot be
instantiated.
06) They need to be marked with the open keyword to be
extended.
29.How do you mark a property to be used only inside
its current class?
01) Use the override keyword.
02) Use the val keyword.
03) Use the private keyword.
04) Use the closed keyword.
05) It is not possible to do this.

30.Select all answers that are true for this XML layout
when displayed on the screen. (You can sketch this out
on a piece of paper first, if that helps.)
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textViewA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textViewB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout
>

Choose as many answers as you see fit.


01) TextView A appears vertically stacked on top
of TextView B.
02) The starting edge of TextView A is aligned to the
starting edge of the parent view.
03) The starting edge of TextView B is aligned to the
starting edge of the parent view.
04) TextView B is horizontally and vertically centered
within the parent.
05) The tops of TextView A and TextView B are aligned
to top of the parent view.
06) The width of TextView A matches the width of the
parent ConstraintLayout.

31.Which line(s) of XML code will produce an error?


1 <TextView
2 android:layout_width="wrap_content"
3 android:layout_height"wrap_content"
4 android:padding="8dp"
5 android:text="@string/title"
6 android:textSize=18sp />

Choose as many answers as you see fit.


01) Line 1 - Missing closing tag > after <TextView.
02) Line 3 - Missing = symbol
after android:layout_height attribute.
03) Line 4 - The android:padding attribute does not exist
for a TextView.
04) Line 5 - You should use @str/title to refer to a string
resource.
05) Line 6 - Missing quotations around the attribute
value 18sp.

32.Which of the following is true about Gradle?


Choose as many answers as you see fit.
01) Gradle is an automated build system used by Android
Studio to build your apps.
02) Gradle handles installing your app on a device.
03) Your app’s build.gradle file is written in XML.
04) You can configure Android-specific options for your
project in your app’s build.gradle file.
05) The gradle configuration for your project cannot
change after you initially create the project.

33.Which of the following statements about app icons


are true?
Choose as many answers as you see fit.
01) It is sufficient to provide a single bitmap image of
your app icon in your project to make it appear high
quality on a range of Android devices.
02) mdpi, hdpi, xhdpi, xxhdpi, and xxxhdpi are density
qualifiers for resource directories to indicate that these are
resources to be used on devices with a specific screen
density.
03) Adaptive icons are made up of a foreground and
background layer, and an OEM mask will be applied on
top of them.
04) Vector drawables only work for a certain screen
density and should not be scaled.
34.Which of the below steps are part of changing the
color of your app theme?
Choose as many answers as you see fit.
01) Modify the themes.xml (night) file.
02) Set the primary and secondary color theme attributes
of your app theme.
03) Define the colors used in your app as color resources
in the colors.xml file.
04) Set the background color of your app in the activity's
layout file.
05) Set the color attribute on all your UI components.
06) Change the name of your theme to your preferred
color.

35.Why use the Material Components for Android


library?
Choose as many answers as you see fit.
01) It provides widgets that follow the Material Design
guidelines such as text fields and switches.
02) It makes your code compile faster.
03) It provides default Material themes that you can use
directly or extend and then customize.
04) It automatically suggests ways for your app to look
better.
05) It helps you more quickly build beautiful user
experiences.

36.Before running the below code, simpleList should


be initialized as a ___ list.
println(simpleList)
simpleList.add(-5)
simpleList.remove(4)
println(simpleList)

01) Int
02) scrollable
03) sorted
04) mutable

37.Which of the following statements are valid?


Choose as many answers as you see fit.
01) val list = listOf(1, 2, 5)
02) val oddNumbers = mutableListOf("1", "9", "15")
03) val listValues: MutableList<Boolean>
04) val fruits = list("apple", "banana", "pear")
05) val words: List<String> = listOf("jump", "run",
"skip")

38.Why does a RecyclerView need an Adapter?


01) To adapt data to display on a specific device type
02) To create a new ViewGroup
03) To adapt data from a data source into JSON
04) To create new ViewHolders and bind data to them

39.Which of the following are advantages to


using RecyclerView?
Choose as many answers as you see fit.
01) RecyclerView comes with built-in layout managers.
02) RecyclerView lets you use packages to organize your
code.
03) RecyclerView helps save processing time, which can
help scrolling through a list smoother.
04) RecyclerView is designed to be efficient for lists by
reusing views that have scrolled off the screen.
05) RecyclerView automatically incorporates Material
Design components.
40.Which of the following is true about packages?
Choose as many answers as you see fit.
01) You can use packages to organize your code.
02) In order to use a class from another package, you have
to explicitly import it in your code.
03) The package name is usually structured from specific
to general.
04) It is good practice to use packages to group classes by
functionality.

41.What should you do to ensure that the correct type


of resource ID is passed in to a constructor?
01) Use an Adapter to force the type.
02) Only use a stringResourceId or imageResourceId.
03) Use resource annotations.
04) Use a naming convention to pass the ID in the
form R.<type>.
05) None of the above

42.Which of the following is false about collections and


higher order functions in Kotlin?
01) Lists, maps, and sets can all use higher order
functions.
02) Lists are unordered, while maps and sets are ordered
data types.
03) Like the elements in a set, the keys in a map must be
unique. However, multiple keys can map to the same
value.
04) Higher order functions such as map and filter can take
lambda functions as parameters.

43.Given the following code, what is the result


of oneWordCities[1]?
val cities = listOf("Jeddah", "Bengaluru",
"Shenzhen", "Abu Dhabi", "Mountain View",
"Tripoli", "Bengaluru", "Lima", "Mandalay",
"Tripoli")
val oneWordCities = cities.toSet().toList().filter {
!it.contains(" ")}.sorted()

01) Tripoli
02) Abu Dhabi
03) Jeddah
04) Bengaluru

44. If you open an app, and then leave the app using
the back button, in which order were the following
activity lifecycle methods called?
01) onStart(), onCreate(), onDestroy(), onStop()
02) onDestroy(), onStart(), onCreate(), onStop()
03) onCreate(), onStart(), onStop(), onDestroy()
04) onStart(), onCreate(), onStop(), onDestroy()

45.Which activity lifecycle method would be called if a


dialog appears onscreen, partially obscuring an
activity?
01) onPause() because the activity is still displayed, but
no longer has focus.
02) onStop() because the activity does not need to
respond to user input while the dialog is onscreen.
03) onResume() because the activity needed to respond to
user input to display the dialog.
04) onDestroy() because the activity does not need to
exist so long as it doesn’t have focus.
46.Which of the following is true about the lifecycle of
a single activity?
Choose as many answers as you see fit.
01) onStart() can be called multiple times,
while onCreate() can only be called once.
02) onStop() can be called multiple times,
while onPause() can only be called once.
03) onDestroy() is called when the app enters the
background.
04) onResume() is called when the activity gains focus.

47.Which of the following is false about intents?


01) Both implicit and explicit intents allow your app to
launch another activity.
02) Explicit intents require you to specify the class of the
activity you want to show.
03) Intents are performed using
the startActivity() method.
04) An implicit intent always results in the system asking
the user which app to open.
48.An activity contains the following code
in onCreate(). What will happen when this code is
executed, if the intent property is null?
val message = intent.extras?.getString("message"
).toString()

01) The app will crash because it attempted to access the


extras property on a null object.
02) The app will crash because it attempted to access a
null object.
03) The app will not crash because the extras property is
accessed unsafely using ?.
04) The app will not crash because the extras property is
accessed safely using ?.
49.Which of the following tasks can be performed
in onCreate()?
Choose as many answers as you see fit.
01) Configuring views, such as setting the layout manager
of a recycler view.
02) Determining the items to be shown in the options
menu.
03) Setting the onClickListener for items in the options
menu.
04) Getting extras from the intent that launched the
activity.

50.In which method should you handle what happens


when a button in the app bar is pressed?
01) onCreateOptionsMenu()
02) openOptionsMenu()
03) onOptionsItemSelected()
04) onPrepareOptionsMenu()

PREPARED BY
ENGINEER MOHAMED ELBEHAIRY
AND
ENGINEER SALMA HESHAM

You might also like