Java Fundamentals: The Java Language (Pluralsight)

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is printed by the following code: for(int i = 1; i > 0; i--) System.out.println(i); 0 and 1 0 Nothing is printed 1

1

Which of the following comments can legally appear within a block comment (/* ...*/)? A line comment or a block comment None of these Another block comment A line comment (comment that starts with //)

A line comment (comment that starts with //)

what does "mutator" mean

A mutator is a method used to control changes to a variable. (AKA a "setter")

Which of the following can legally be returned from a method? A primitive type, reference to an object, or reference to an array A reference to an array, reference to an object, but not a primitive type A primitive type, reference to an array, but not a reference to an object A primitive type, reference to an object, but not a reference to an array

A primitive type, reference to an object, or reference to an array

what does "accessor" mean

Another name for "getter".

For which of the following is it valid to have no access modifier? Types only Type members only Any type or member Only members of types marked as private

Any type or member

How does one create a package name that is globally unique? By registering the package name with Oracle By following the convention of using a reversed domain name (i.e. com.pluralsight) By using the JDK to generate the package name By using a Java IDE to generate the package name

By following the convention of using a reversed domain name (i.e. com.pluralsight)

Given the following class definitions... public class Class1 { final void myMethod() { // ... } } public class Class2 { abstract void myMethod() ; } Which class needs to be marked with the same modifier (final or abstract) as the class's corresponding myMethod method? Neither Class1 or Class2 Class1 Class1 and Class 2 Class2

Class2

Given the following two class definitions: class Class1 { public void theMethod(int theVal) {/* implementation elided */} public void theMethod(short theVal) {/* implementation elided */} } class Class2 { public void theMethod(int theVal) {/* implementation elided */} public short theMethod(int theVal) {/* implementation elided */} } Which statement is true? Neither Class1 or Class2 contain an invalid method overload Class1 contains an invalid method overload Class2 contains an invalid method overload Both Class1 and Class2 contain an invalid method overload

Class2 contains an invalid method overload

What is the concept of overloading in java?

Creating multiple methods or constructors with the same name, but different parameters.

What does "invalid method overload" mean

Creating two methods with the same name, but different types.

Which of the following must be true for a class with multiple constructors? Each constructor must have a different parameter list All of these Each constructor must have a different name Each constructor must have a different return type

Each constructor must have a different parameter list

What does super do?

It allows us to call a constructor from the extended class.

Which of the following best describes Java? It is a language. None of these. It is both a language and a runtime environment. It is a runtime environment.

It is both a language and a runtime environment.

Given the following class declaration: class Person { public int age; private int height; public Person(int age) { // code elided } public Person(int age, int height) { // code elided } } If the constructor with two arguments calls the constructor with one argument, which of the following must be true about the call? It must be the first line of code within the body of the calling constructor It must be the last line of code within the body of the calling constructor It must appear prior to the opening bracket of the calling constructor It can appear anywhere within the body of the calling constructor

It must be the first line of code within the body of the calling constructor

What does JDK stand for?

Java Development Kit

What does JRE stand for?

Java Runtime Environment

Which of the following are interfaces permitted to include? Methods and constructors Methods only Methods and constants Methods, constants, and constructors

Methods and constants

When one class extends another, which constructor(s) are inherited by the derived class from the base class? No constructors are inherited Only the constructor with no arguments All constructors are inherited Only the constructors marked with @Override

No constructors are inherited

Given the following class definition... public class MyClass { public boolean clone(Object o) { return false; } } What is displayed by the following code? MyClass c1 = new MyClass(); MyClass c2 = new MyClass(); if(c1 == c2) System.out.print("A"); if(c1.equals(c2)) System.out.print("B"); AB A Nothing is printed B

Nothing is printed == and .equals both perform reference check for class objects, unless we override equals method

What is boxing?

Primitive to wrapper Integer d = Integer.valueOf(100);

At what point in a class lifecycle in a static initialization block called? Each time a class instance is created When the first clas instance is created At program start Prior to the class' first use

Prior to the class' first use

What is a "primitive wrapper class"?

Similar to the primitive types, but in the form of a class. Use capital letter, example. Integer i = Integer.valueOf(100);

Which of the following statements is true regarding a try/catch statement containing multiple catch blocks? The catch blocks must be ordered to catch the most specific exceptions first. It is an error to have a try/catch with multiple catch blocks. The catch blocks must be ordered to catch the least specific exceptions first. The order of the catch blocks doesn't matter.

The catch blocks must be ordered to catch the most specific exceptions first.

What is the base class.

The class that is extended, which inherits classes from previous classes.

What is an initialization block?

The group of code that contains initializations outside of all constructors. The initialization block executes before any constructors.

Given the following two class definitions: public class MyClass { public void myMethod(double val1, double val2) {/* implementation elided */} public void myMethod(int val1, int val2) {/* implementation elided */} } Which statement is true about the following code? MyClass m = new MyClass(); long x = 10; long y = 20; m.myMethod(x, y); An error is generated because both myMethod overloads are valid to call The myMethod overload accepting two doubles is called The myMethod overload accepting two ints is called An error is generated because neither myMethod overload is valid to call

The myMethod overload accepting two doubles is called

Given the following class definitions... public class MyBase { int iVal = 5; } public class MyDerived extends MyBase { int iVal = 10; } Which statement is true about the following code? MyDerived var = new MyDerived(); System.out.println(var.iVal); The value displayed is indeterminate. The value 10 will be displayed. The code will generate an error. The value 5 will be displayed.

The value 10 will be displayed.

What does "Parameter Immutability" mean

When passing a primitive type variable into a method, the original values passed in are not changed. This is called passing by value.

In which of the following cases is a method permitted to NOT have an implementation? When the method is abstract When the method is part of a class marked final When the method is final When the method is public

When the method is abstract

Which of the following should always be done when throwing one exception in response to another? a) The original exception should be discarded. b) Be sure that there's a finally block associated with the try/catch that handled the original exception. c) The original exception should be associated with the new exception. d) There are no specific requirements.

c) The original exception should be associated with the new exception.

Name 4 types of access modifiers

default, private, protected, public,

Given the following code, which variable assignment(s) involve(s) a primitive wrapper class? Integer i1 = 100; int i2 = 100; Object o1 = 100; i1 and i2 o1 and i2 i1 i1 and o1 i1, i2, and o1

i1 and o1

Given the following, which variable is being validly set in the constructor? public class MyClass { private final int iVal1; private static final int iVal2; public MyClass() { iVal1 = 1; iVal2 = 2; } } iVal1 iVal2 Neither iVal1 or iVal2 Both iVal1 and iVal2

iVal1

Given the following code, which variable(s) is/are set most efficiently? String city = "London";" String s1 = "Hello"; s1 += " "; s1 += "World"; s1 += " "; s1 += "from"; s1 += " "; s1 += city; StringBuilder sb = new StringBuilder(25); sb.append(" "); sb.append("World"); sb.append(" "); sb.append("from"); sb.append(" "); sb.append(city); String s2 sb.toString(); The result is indeterminate s1 s2 Both s1 and s2 are equally efficient

s2

What does "short" mean (used instead of void)

short is an integer type in java

What is unboxing?

wrapper to Primitive int e = d.intValue();

does super have to be first line in code when called?

yes


संबंधित स्टडी सेट्स

Foundational Concepts Review - BEHA 5455

View Set

Physics 1320 test 1 Study Questions

View Set

Cultural Anthropology Final Exam Quiz Review from Nest in the Wind

View Set

NUR 111 Unit 5 Health, Wellness & Illness Module 20

View Set

CJ 322 Public leadership Ch 10-16

View Set