Java

¡Supera tus tareas y exámenes ahora con Quizwiz!

if else statement

Its an else statement

What are the types of decision making statements? (4)

1. If statement 2. if else statement 3. nested statement 4. switch statement

Using "super" to invoke parent class method

The super keyword can also be used to invoke parent class method. It should be used if subclass contains the same method as parent class. In other words, it is used if method is overridden.

Using "super" to invoke parent class constructor

The super keyword can also be used to invoke the parent class constructor.

Usage of "super" keyword

The super keyword in Java is a reference variable which is used to refer immediate parent class object.

"this" : to refer current class instance variable

The this keyword can be used to refer current class instance variable. If there is ambiguity between the instance variables and parameters, this keyword resolves the problem of ambiguity. this.title=title;

"this" : to invoke current class constructor

The this() constructor call can be used to invoke the current class constructor. It is used to reuse the constructor. In other words, it is used for constructor chaining

What variable can be used for switch statements?

The variable used in a switch statement can only be integers, convertable integers (byte, short, char), strings and enums.

What are the types of loops? (3)

1. While loop 2. for loop 3. do while loop

What can a "super" class be used for? (3)

1. super can be used to refer immediate parent class instance variable. 2. super can be used to invoke immediate parent class method. 3.super() can be used to invoke immediate parent class constructor.

What are the 6 usages of the keyword "this"?

1. this can be used to refer current class instance variable. 2. this can be used to invoke current class method (implicitly) 3. this() can be used to invoke current class constructor. 4. this can be passed as an argument in the method call. 5. this can be passed as argument in the constructor call. 6. this can be used to return the current class instance from the method.

What is a "do while loop"

A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.

What is a "for loop"

A for loop is a repetition control structure that allows you to efficiently write a loop that needs to be executed a specific number of times

What is a loop?

A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages.

Switch statement

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.

What is a "While loop"?

A while loop statement in Java programming language repeatedly executes a target statement as long as a given condition is true.

if else statement

An if statement can be followed by an optional else statement, which executes when the Boolean expression is false.

If statement

An if statement consists of a Boolean expression followed by one or more statements If the Boolean expression evaluates to true then the block of code inside the if statement will be executed. If not, the first set of code after the end of the if statement (after the closing curly brace) will be executed.

Parts of the "new" keyword

Declaration : First, you must declare a variable of the class type. This variable does not define an object. Instantiation and Initialization : Second, you must acquire an actual, physical copy of the object and assign it to that variable. You can do this using the new operator. The new operator instantiates a class by dynamically allocating(i.e, allocation at run time) memory for a new object and returning a reference to that memory. This reference is then stored in the variable. Thus, in Java, all class objects must be dynamically allocated. The new operator is also followed by a call to a class constructor, which initializes the new object. A constructor defines what occurs when an object of a class is created. Constructors are an important part of all classes and have many significant attributes. ex. Student brandon = new Student();

What are two parts to an "Enhanced For Loop"?

Declaration − The newly declared block variable, is of a type compatible with the elements of the array you are accessing. The variable will be available within the for block and its value would be the same as the current array element. Expression − This evaluates to the array you need to loop through. The expression can be an array variable or method call that returns an array.

How does a "while loop" work?

When executing, if the boolean_expression result is true, then the actions inside the loop will be executed. This will continue as long as the expression result is true. When the condition becomes false, program control passes to the line immediately following the loop.

Usage of the "new" keyword

When you are declaring a class in java, you are just creating a new data type. A class provides the blueprint for objects. You can create an object from a class

"this" : to invoke current class method

You may invoke the method of the current class by using the this keyword. If you don't use the this keyword, compiler automatically adds this keyword while invoking the method.

What must follow each case in a switch statement?

break; or the code will not terminate the default does not require a break

What is a decision making structure?

has one or more conditions to be evaluated by the program along with a statement to be executed if determined to be true. i.e. if statement, if else, nested, switch

How does a "do while loop" work?

the Boolean expression appears at the end of the loop, so the statements in the loop execute once before the Boolean is tested. If the Boolean expression is true, the control jumps back up to do statement, and the statements in the loop execute again. This process repeats until the Boolean expression is false.

What is an "Enhanced For Loop"?

As of Java 5, the enhanced for loop was introduced. This is mainly used to traverse collection of elements including arrays.

nested if statement

It is always legal to nest if-else statements which means you can use one if or else if statement inside another if or else if statement.

How does a "for loop" work?

The initialization step is executed first, and only once. This step allows you to declare and initialize any loop control variables and this step ends with a semi colon (;). Next, the Boolean expression is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop will not be executed and control jumps to the next statement past the for loop. After the body of the for loop gets executed, the control jumps back up to the update statement. This statement allows you to update any loop control variables. This statement can be left blank with a semicolon at the end. The Boolean expression is now evaluated again. If it is true, the loop executes and the process repeats (body of loop, then update step, then Boolean expression). After the Boolean expression is false, the for loop terminates.

Using "super" to refer parent class instance variable

We can use super keyword to access the data member or field of parent class. It is used if parent class and child class have same fields.


Conjuntos de estudio relacionados

Chapter 16: Spirituality Practice Questions

View Set

Chapter 12 vocabulary study guide

View Set