PROGRAMMING WEEK 11-20

Programming Grade 11 (PROG-111) Week 11-20 Exams and Quizzes

Programming Grade 11 (PROG-111) Week 11-20 Exams and Quizzes

AMALEAKS ANSWER

Java Programming Quiz

Observe the following statements and decide whether the variable result’s value is TRUE or FALSE. Given that: int x = -77; int z = 43; result = (z < x && 1 != 10) ? true : false; result = (z != 43) ? true : false;

Answer: False

True or False: The last line of code, with a close brace { symbol, is properly indented.

Answer: False

True or False: Brackets [] are also separators used in declaring arrays.

Answer: True

Refer to the block of codes below. Read each statement carefully and decide whether it’s TRUE or FALSE. There is an error in line 9.

Answer: True

True or False: Operators, in Java programming language, use special symbols to call methods and their objects.

Answer: False

Read each statement carefully and decide whether it’s TRUE or FALSE. There are no errors in the program.

Answer: False

Refer to the block of codes below. Read each statement carefully and decide whether it’s TRUE or FALSE. Line 9 uses a traditional comment which uses double forward slash.

Answer: False

True or False: Many programmers can be literate with Java programming language for it is intended to be that way.

Answer: True

True or False: You’ll know there’s an error if you see a red circle with an exclamation point in Netbeans IDE.

Answer: True

Observe the following statements and decide whether the variable result’s value is TRUE or FALSE. Given that: int x = -77; int z = 43; result = (z < x && 1 != 10) ? true : false; result = (x = 100) >= z;

Answer: True

The file is accurately named – Students.java.

Answer: False

There are three (3) separators found in line 13.

Answer: False

There is an error in line 9.

Answer: True

result = 90 < x || -1 < z;

Answer: True

The last line of code, with a close brace { symbol, is properly indented.

Answer: False

Assuming there are no errors in the code, line 13 would display When I graduate, I’d be 18.

Answer: True

Figure 2 shows the Netbeans Integrated Development Environment.

Answer: True

The last line of code will output 100.0.

Answer: True

True or False: An exclamation point in Java means NOT. Therefore, != means not equal to.

Answer: True

There are two types of comments used in the program above – end of line and Javadoc comments.

Answer: True

result = (z < x && 1 != 10) ? true : false;

Answer: False

There are keywords found in line 7.

Answer: True

In line 11, the value of personage is 18.

Answer: True

If there are no errors in the program, the first line of output would read Hi, I’m a normal person.

Answer: False

result = (x * z + (z += 7)) >= 100;

Answer: False

True or False: Logical OR operator will result to false if one of the expressions is false.

Answer: False

True or False: Semicolon (;) is a separator used to end a Java statement.

Answer: True

True or False: There are five types of integer data types – byte, short, int, long and float.

Answer: False

True or False: Single equal sign (=) is used for assigning values while double equal sign (==) is used in comparing values.

Answer: True

True or False: Java’s ternary operator is a short hand for the if-then-else statement which uses a question mark and a colon.

Answer: True

True or False: JDK or Java Design Kit is required to compile and run Java apps and applets.

Answer: True

On line 6, average is equal to 0. But on line 9, average will be equal to 100.

Answer: False

True or False: Identifiers in Java are, in simple words, name that you give to Java class, variables and methods.

Answer: True

True or False: When you run javac in a command line interface, it will automatically create another file with a filename extension .class.

Answer: True

Line 9 uses a traditional comment which uses double forward slash.

Answer: False

There are five (5) separators used in line 8.

Answer: True

There are no errors on line 8.

Answer: False

True or False: Syntax is basically the spelling and grammar errors compiled in a Java programming language. It should be avoided in writing apps and applets.

Answer: False

True or False: Operators, in Java programming language, use special symbols to call methods and their objects.

Answer: False

If you run this program, the second line of output will read Your score is:.

Answer: True

True or False: Java is a low level programming language.

Answer: False

There are also punctuators used in line 10, in between System, out and println, the parentheses and semicolon.

Answer: True

If there are no errors and this simple program runs through CLI, the first line will display: Hi, students!

Answer: False

True or False: Brackets [] are also separators used in declaring arrays.

Answer: True

Substrings can contain 1 or 2 arguments.

Answer: True

Determine the output. [String manipulation]

Answer: bar

The index of the letter “y” in string “Doggy” is 5.

Answer: False

Determine the output. [String manipulation]

Answer: foo

True or False: The value “val_3” is a white space “ “.

Answer: False

True or False: Variable 1st_num is a good variable name in Java programming.

Answer: False

True or False: “val_2” contains “The”.

Answer: True

True or False: Instance variables are declared inside a method but outside a class.

Answer: False

True or False: Variable names in Java are not necessarily case sensitive.

Answer: False

Determine the output. [Arithmetic operation]

Answer: 36

True or False: Public, private and protected are some of the return types used in Java programming.

Answer: False

True or False: Divide and conquer strategy, in programming, is also known as the top-down design.

Answer: True

If there are no errors in the program, line 9 would display I weigh 160.

Answer: False

True or False: A boolean variable can only have two values; it is either true or false.

Answer: True

result = !((x * 10) < z);

Answer: False

result = -(-z) == 43;

Answer: True

True or False: If you get an error while running the javac command in the CLI, it could be resolved by editing the Path value in Environment Variables.

Answer: True

True or False: The subtraction assignment operator subtracts the left and right operand and assigns the difference to the operand at the right.

Answer: False

x += x; result = x == 154;

Answer: False

The second line of output will be: You are in Year 11.

Answer: True

True or False: The conditional AND operator uses two ampersand (&&) symbols.

Answer: True

result = 43 <= z;

Answer: True

True or False: You’ll know that a variable is a class variable when you see that variable inside a class with the word static.

Answer: True

The string method “length( )” returns the number of characters within a string.

Answer: True

A string can contain numbers.

Answer: True

True or False: This is an example of concatenation.

Answer: True

True or False: The value of “val_4” is “fox”.

Answer: False

True or False: “val_2” contains “The”.

Answer: True

Determine the output. [String manipulation]

Answer: f6

Languages which use procedural programming include C, (Answer) FORTRAN, Pascal and BASIC.

Answer: C++

True or False: Local variables are declared inside the default method.

Answer: False

Strings can be declared with str.

Answer: False

True or False: Procedural programming involves instructing the system as to how to complete a task.

Answer: True

True or False: The output of this code is “The quick brown fox”.

Answer: False

Among the expressions below which is a statement?

Answer: True

Expressions can be long and complex.

Answer: True

number++; is an expression.

Answer: True

For-loops has a set number of iterations before starting.

Answer: True

The equals( ) method can compare more than 2 arrays.

Answer: False

While loops can use Booleans at test expressions.

Answer: True

The test expression of the if statement is _______.

Answer: less than or equal to

There are four (4) major features of an object-oriented programming language – encapsulation, inheritance, polymorphism and abstraction.

Answer: True

Using a break; statement causes the loop to jump to the next iteration.

Answer: False

x+1 is example of a statement.

Answer: False

number++; is a block.

Answer: False

Arrays are

Answer: Objects

The operator “new” allocates a memory block the size of what is declared.

Answer: True

A class block can be an expression.

Answer: False

Statements can be expressions.

Answer: False

Integer arrays can be populated with characters.

Answer: False

Declaration clauses are declared as “number + 1”.

Answer: False

Loops can be stopped with a break; statement.

Answer: True

The equivalent of Paragraphs in coding is?

Answer: Expressions

If statements cannot be nested in switches.

Answer: True

The length( ) method returns the size (number of indices) has.

Answer: True

When polymorphism is used, the Java object can only take one form. Subclasses should have the same function with the parent class.

Answer: False

Arrays can contain (Answer) number of elements.

Answer: Any

“||” and “&&” can be used in conditional statements.

Answer: True

A class statement has three (3) major parts – declaration, initialization and instantiation.

Answer: False

Declaring an object in Java uses the new keyword to create a new object.

Answer: False

Please refer to Figure 2 to answer the question below: If the expression “num = 0” is changed to “num = 5” the final output will be

Answer: 5

Expressions can be statements.

Answer: True

Blocks can contain more blocks of code.

Answer: True

If-else statements can be nested in?

Answer: All of the choices

Statements are equivalent to paragraphs.

Answer: False

A (answer) array is an array containing true or false values.

Answer: boolean

Switches are always used with if-else statements.

Answer: False

True or False: The modulus operator returns the remainder of a division operation instead of the quotient.

Answer: True

Determine the output. String val_1 = “564298”;

Answer: 5698

Determine the output. String val_1 = “35”;

Answer: 4

The return value of the length( ) method is an integer.

Answer: True

A superclass is also known as a parent class.

Answer: True

For-loops can be nested in while loops.

Answer: True

In instantiating an object, the keyword instance is used.

Answer: False

Object oriented programming utilizes the top down method.

Answer: False

Expressions are like clauses.

Answer: True

The sort( ) method is always ascending.

Answer: True

Arrays are data types.

Answer: False

Variables must be declared as (Answer) for it to be fully hidden.

Answer: private

While statements check the test expression at the end.

Answer: False

The else statement can be used alone.

Answer: False

The fill( ) method (Answer) the array with specific values.

Answer: Fills

The output of println is

Answer: 55555

The person’s weight is declared correctly with the correct data type (byte) and value (160).

Answer: False

Determine the output. String val_1 = “foo”; String val_2 = “bar”; val_2 = val_1; val_1 = val_3; System.out.println(val_1);

Answer: bar

Determine the output. String val_1 = “foo”; String val_2 = “bar”; val_2 = val_1; val_1 = val_3; System.out.println(val_2);

Answer: foo

Switches can work properly even without the “break” expression.

Answer: True

Blocks can be one liner or huge classes.

Answer: True

The test expressions in conditional statements can be left empty.

Answer: False

Abstraction works by hiding the implementation details and showing only the functions necessary.

Answer: True

A single array can hold multiple data types.

Answer: False

A polymorphic object can pass more than one Is-a test.

Answer: True

Another loop can be used as test expression.

Answer: False

True or False: Public, static and void are sample of Java reserved keywords.

Answer: True

The value of “pStr” in line 24 is

Answer: True

The default syntax of a constructor is <class_name>(parameter, parameter){ }

Answer: False

A nested class is not an inner class.

Answer: False

Nested classes causes them to become abstracted.

Answer: False

A nested class is also called

Answer: inner class

If you want some variables and methods hidden from other classes, you could implement encapsulation where these variables and methods are wrapped in a single unit.

Answer: True

A constructor can only have 1-2 overloads or parameters.

Answer: False

All possible data types of an array can be returned as a string by the toString( ) method.

Answer: True

Abstracted classes can contain 1 or more abstract methods.

Answer: True

Abstraction shows the every bit of detail and implementation on how an application does something.

Answer: False

Initialization is a process where the constructor is called for.

Answer: True

The default syntax of a constructor is <class_name>( ){ }

Answer: True

Classes cannot be nested.

Answer: False

Abstract classes cannot have nested classes.

Answer: False

The parent class of a nested class is called an outer class.

Answer: True

An inner class can be constructed directly without reference to the outer class.

Answer: False

Arrays can be read backwards.

Answer: True

A single array can hold

Answer: One data type

Abstracted methods already have implementations inside.

Answer: False

are special methods to initialize objects.

Answer: constructors

Constructors have 3 basic rules to follow.

Answer: False

Nesting classes increases encapsulation.

Answer: True

Each index can only contain (Answer) element.

Answer: one

The sort( ) method can be set to sort only a part of an array.

Answer: False

Subclasses or child classes could have different behaviors but still share the same functions from their parent class.

Answer: True

Abstract methods must have an explicit return value.

Answer: False

An abstract class must not contain abstract methods.

Answer: False

Abstracted classes can be nested.

Answer: True

A subclass constructor cannot invoke a superclass constructor.

Answer: False

A class acquiring fields and methods of another class is called inheritance.

Answer: True

Parallelsorting utilizes

Answer: More cpu processing cores

method can copy one array to another.

Answer: arraycopy()

Conditional test expressions can contain declarations.

Answer: True

A child class inherits all the methods of every other class.

Answer: False

If the value of “pStr” in line 7 is changed to _______ then the value of “pStr” in line 24 will be changed as well.

Answer: True

The type of loop that checks the test expression at the end.

Answer: do-while

An array of integers should be declared as

Answer: int[]

A class which contains the abstract keyword in its declaration is known as an

Answer: abstract class

Please refer to figure 1 to answer the question below: In figure 1 if(x==5) is

Answer: skipped

The first line of the code should have either a yes or no value.

Answer: False

Determine the output. String val_1 = “25”; String val_2 = “80”;

Answer: 200

What does ‘new’ in int[ ] myArray = new int[n] do?

Answer: Assigns memory for the array

is also known as a parent class.

Answer: Super class

Determine the output. String val_1 = “foobar”; String val_2 = “”;

Answer: boar

Polymorphic objects can pass (answer) Is-a test.

Answer: More than one

True or False: Traditional comments start with /** (forward slash and two asterisks) and ends with */ (asterisk and forward slash).

Answer: False

True or False: Netbeans is one of the IDEs or Integrated Development Environment to run Java programs.

Answer: True

For-loops can check the test expression at the end.

Answer: False

Polymorphism is the ability of a Java object to take

Answer: Directly

Constructors can have

Answer: any number

When the program runs, and assuming there are no errors, its first line will be begin printing.

Answer: False

Which of these is a proper decrement?

Answer: x-10;

All are methods of the array class except

Answer: substring()

The error in Figure 2 is

Answer: “tralse”;

A constructor (answer) contain an explicit return type.

Answer: cannot

Abstracted methods need (answer) for implementations.

Answer: sub-classes

Line 14 will yield an error. It will be corrected if you place */ after the method.

Answer: False

The name of a constructor must be (answer) as your class.

Answer: same

The limit of dimensions an array can have without errors is

Answer: 255

This type of declaration is discouraged.

Answer: String myArray[];

The following figure shows the Netbeans Integrated Development Environment.

Answer: True

The equivalent of clauses in coding is?

Answer: Expressions

Int num = 1; for(num=num;num<=10;num++) is an acceptable code snippet.

Answer: True

Loop that has a pre-determined number of iterations

Answer: while

An int can be used even if it is declared outside a for-loop.

Answer: True

Overload methods must be the same name as the class.

Answer: True

What the break statement in this example does is ________.

Answer: Ends the whole instance of the loop

The random( ) method sorts the array randomly.

Answer: False

The last part in a for loop setup can be an ________.

Answer: both

The “1” in arrayName[1] is called an ________.

Answer: Index

The continue; statement ends all the iterations of a loop.

Answer: False

Which is not a proper increment?

Answer: n+-;

Infinite for-loops can be declared as for( ){ }.

Answer: False

If-if is more logical than else-if.

Answer: False

The else statement can be removed if not needed.

Answer: True

Expressions, Statements and Blocks are like composing sentences and paragraphs.

Answer: True

You can declare a new method in the subclass which is not declared in the superclass.

Answer: True

The return value of the equals( ) method is ________.

Answer: None of the choices

The Arrays.sort( ) method sorts an array into _________ order.

Answer: Ascending

This type of declaration is discouraged: “int myArray[]”

Answer: True

An if-else-if-else statement is a block.

Answer: True

If the increment num=num+2 is changed to num++, the final value of num will be ________.

Answer: 5

The term of each pass through a loop makes is called?

Answer: iteration

Loops must always have a continue or break statement.

Answer: False

1+2+3/4*5 is an unambiguous expression.

Answer: False

Conditional statements can contain more conditional statements.

Answer: True

int num = 1; if(num==1 && num<=1){body;} The conditional statement will _______.

Answer: execute the body

byte[][][] myArray; is an example of ________.

Answer: An error

An array _______ hold objects.

Answer: can

A reference variable can be reassigned to other objects provided that it is not declared ________.

Answer: final

The test expression of conditional statement cannot contain _______

Answer: !

Each pass through of a loop is called a cycle.

Answer: True

If the increment “num = num + 2” is changed to “num = num + 1” the final output will be _______.

Answer: 0

Ifs and else-ifs test expressions return true or false.

Answer: True

_______ classes increase the encapsulation of you methods and data.

Answer: nesting

Constructed methods are initialized with 0 or null depending on the data type.

Answer: True

The else statement catches whatever argument the if and else-if didn’t.

Answer: True

An iteration of a loop is equivalent to one pass through.

Answer: True

If we change the initial value of num in line 6 to “num = 0”, the println output will be _______

Answer: 0

The else-if statement can be used alone.

Answer: False

Abstract methods need sub-classes to contain their implementations.

Answer: True

The method arraycopy( ) does what?

Answer: Copies the contents of an array to a destination array.

An array can be infinitely long.

Answer: False

A loop can contain no expressions or statements inside.

Answer: True

Conditional statements are the same as declaration statements.

Answer: False

You cannot use inherited methods directly in a child class.

Answer: False

The equals( ) method compares 2 arrays.

Answer: True

Method invocations are statements.

Answer: True

To implement encapsulation, you have to declare class variables with the private modifier.

Answer: True

Inner class methods can be called by constructing the inner class.

Answer: False

Encapsulated data are hidden from other classes.

Answer: True

Refer to the code snippet below. Identify what part of a method is shown in each number (the underlined one). GIVEN: public int ____getArea__

Answer: Method Name

Fill in the blanks with the correct answer. [String concatenation]

Answer: val_1 + val_2

Read each statement carefully and decide whether it’s TRUE or FALSE. The filename of the Java file above is computesum.java.

Answer: False

Refer to the code snippet below. Identify what part of a method is shown in each number (the underlined one). GIVEN: int getArea

Answer: Return Type

Fill in the blank: [String manipulation]

Answer: foo

Procedural programming will be tricky for applications.

Answer: small

Strings can directly concatenated to an int.

Answer: False

True or False: The value of “val_3” is 3.

Answer: False

Fill in the blank: [String concatenation]

Answer: barfoo

Refer to the code snippet below. Determine whether the given is a local variable, instance variable, access modifier or a class name. GIVEN: private class EmployeeRecord

Answer: access modifier

True or False: The assigned values of “val_1” & “val_2” are integers.

Answer: False

Fill in the blank: [Arithmetic operation]

Answer: 200

True or False: A method could be declared without any parameters.

Answer: False

Fill in the blank: [String manipulation]

Answer: foo

Refer to the block of codes below. Read each statement carefully and decide whether it’s TRUE or FALSE. There are no errors in line 11.

Answer: True

Determine the output. [Code with error]

Answer: error

True or False: Non-procedural programming focuses on how a task is done rather than on what task should be done.

Answer: False

Refer to the code snippet below. Determine whether the given is a local variable, instance variable, access modifier or a class name. GIVEN: private class ____EmployeeRecord__

Answer: class name

Determine the output. [String concatenation]

Answer: chocolate bar

True or False: If you are running a program through CLI, the class name and the file name should be different.

Answer: False

Fill in the blank: [String length]

Answer: 6

The “indexOf( )” method returns the first instance of the specified character.

Answer: True

Please refer to figure 1 to answer the question below: If we change the initial value of num in line 6 to “num = 0”, the println output will be

Answer: 0

Strings can readily accept int values.

Answer: True

True or False: Keywords are Java reserved words which are used as identifier for interface, constants and constructs.

Answer: True

Refer to the code snippet below. Determine whether the given is a local variable, instance variable, access modifier or a class name. GIVEN: ____int noOfEmployee__

Answer: local variable

True or False: After compiling a Java program through the CLI, run it using the java and press Enter.

Answer: True

Refer to the program below. Read each statement carefully and write the output for each line specified. Line 22 will display on the screen.

Answer: 1

Frequently Asked Questions

What is the purpose of the Java Development Kit (JDK)?

The JDK is a software development environment used for developing Java applications and applets. It includes the Java compiler (javac), the Java Runtime Environment (JRE), and other tools needed to compile and run Java programs.

What are the main features of object-oriented programming in Java?

Java supports four main features of object-oriented programming: encapsulation (hiding data within a class), inheritance (allowing classes to inherit properties from other classes), polymorphism (allowing objects to take multiple forms), and abstraction (hiding complex implementation details).

What is the difference between procedural and object-oriented programming?

Procedural programming focuses on procedures or functions to complete tasks in a step-by-step manner, while object-oriented programming organizes code into objects that encapsulate data and behavior, promoting modularity and reusability.

Why is Netbeans IDE commonly used for Java programming?

Netbeans is a popular Integrated Development Environment (IDE) for Java because it provides a user-friendly interface, code debugging tools, code completion, and support for multiple programming languages, making it easier to write, test, and deploy Java applications.

What is the significance of arrays in Java?

Arrays in Java are used to store multiple values of the same data type in a single variable. They are objects that allow efficient data management and manipulation, supporting operations like sorting, searching, and iteration.

Previous Post Next Post