Tuesday, May 6, 2014

Java Final




Attempt 1
Written: Mar 4, 2014 3:37 PM - Mar 4, 2014 4:34 PM
Submission View
Question 1

4 / 4 points
Which of the following are Java IDE development tools?

Correct Response
google

Correct Response
Eclipse

Correct Response
yahoo

Correct Response
DrJava
Question 2

5 / 5 points







Write java code to define an interface called ValuableAsset.

The
interface should have one method called getMarketValue.

The method
getMarketValue takes no parameters and returns the value, in dollars, of the asset that implements this interface.
Public class getMarketValue extends ValuableAsset {
getMarketValue = ValuableAsset
Public double getMarketValue();
}
The correct answer is not displayed for Long Answer type questions.
Question 3

2 / 2 points
Consider the following java classes ( GreenBuilding and GGCbuilding):




public class GreenBuilding implements EnergyEfficiency, ValuableAsset


public class GGCbuilding extends GreenBuilding



Is the following statement correct in java?


      ValuableAsset  xBuilding = new GGCbuilding();
Correct Response
True

False
Question 4

1 / 1 point






Consider the following java classes ( GreenBuilding and GGCbuilding):




public class GreenBuilding implements EnergyEfficiency, ValuableAsset


public class GGCbuilding extends GreenBuilding



Is the following statement correct in java?


      EnergyEfficiency  yBuilding = new GGCbuilding();
Correct Response
True

False
Question 5

2 / 2 points






Consider the following java classes ( GreenBuilding and GGCbuilding):




public class GreenBuilding implements EnergyEfficiency, ValuableAsset


public class GGCbuilding extends GreenBuilding



Is the following statement correct in java?


       ValuableAsset  zBuilding = new EnergyEfficiency();


True
Correct Response
False
Question 6

2 / 2 points






Which of the following statements is correct?


A class can implement only one interface type.

All fields in an interface are private.

A class can NOT implement an interface type.
Correct Response
A class can implement more than one interface type.
Question 7

2 / 2 points






Which of the following is true regarding subclasses?

A subclass inherits methods from its superclass but not instance variables.

A subclass does not inherit methods or instance variables from its superclass.
Correct Response
A subclass inherits methods and instance variables from its superclass.

A subclass inherits instance variables from its superclass but not methods.
Question 8

2 / 2 points






Use the
___super___Correct Response
keyword to call a constructor in the superclass.
Question 9

2 / 2 points
Interface and Class are interchangeable terms.

True
Correct Response
False
Question 10

2 / 2 points






A java class can have more than one super class by using
public class MyClass extends ClassA, ClassB, ClassC
{
}


True
Correct Response
False
Question 11

4 / 4 points






The following question refers to the following code:

Treat.java

HairballRemedy.java

ScoobyTreat.java





public interface Treat
{
        String getColor();
        String getSize();
}




public class HairballRemedy implements Treat
{
        public String getColor()
        {
               return "blue";
        }

        public String getSize()
        {
               return "0.5 oz";
        }
}




public class ScoobyTreat implements Treat
{
        public String getColor()
        {
               return "green";
        }

        public String getSize()
        {
               return "2 oz";
        }
}







Munchies.java





public class Munchies
{
        public static void main(String[] args)
        {
               HairballRemedy a=new HairballRemedy();
               ScoobyTreat b=new ScoobyTreat();
               Treat c=a;
               Treat d=b;
               System.out.println(a.getColor());
               System.out.println(b.getColor());
               System.out.println(c.getColor());
               System.out.println(d.getColor());            
        }
}




When running Munchies, the output is four lines. In each of the four lines blanks below, provide the output.
___blue___Correct Response(25 %)

___green___Correct Response(25 %)

___blue___Correct Response(25 %)

___green___Correct Response(25 %)

Question 12

4 / 4 points
7. To use an interface, a class header should include which of the following?
Correct Response
The keyword implements and the name of the interface

The keyword extends and the name of the interface

The keyword implements and the name of an abstract method in the interface

The keyword extends and the name of an abstract method in the interface
Question 13

2 / 2 points






_____________is defined as the behavior can vary depending on the actual type of an object .

Packaging
Correct Response
Polymorphism

Casting

Instantiation
Question 14

2 / 2 points






____ occurs when a single class has several methods with the same name but different parameter types.
Correct Response
Overloading

Inheritance

Instantiation

Casting
Question 15

2 / 2 points






Inheritance is the ability to define a new class using an existing class as the basis.
Correct Response
True

False
Question 16

2 / 2 points






The
___extends___Correct Response
keyword is used in Java for deriving a subclass from an existing class.
Question 17

2 / 2 points
In Java, a class that is defined without an explicit extends clause


has no superclass
Correct Response
is a subclass of Object

is a syntax error

is its own superclass
Question 18

2 / 2 points






When declared as protected, data in a class cannot be accessed by all of its subclasses.

True
Correct Response
False
Question 19

2 / 2 points






When declared as protected, methods in a class can only be accessed by all of its subclasses.

True
Correct Response
False
Question 20

4 / 4 points






Match the following with the best answer:
Correct Response
__2__

A method that is invoked by a class is
Correct Response
__1__

A method that is invoked by an object is

1.
instance
2.
static
Question 21

0 / 4 points






Match the following with the appropriate term using the code below:

public class Son extends Dad
{
}
Incorrect Response
__2__
(1)
Son
Incorrect Response
__1__
(2)
Dad

1.
subclass
2.
superclass
Question 22

2 / 2 points






Consider the following java classes ( Building and Skyscraper):




public class Building
{
      String address = "1234 Main St";
}



public class Skyscraper extends Building
{
      int topFL = 101;
}




Is the following statement correct in java?


      Building  mybuilding = new Skyscraper();

Correct Response
True

False
Question 23

2 / 2 points






Consider the following java classes ( Building and Skyscraper):




public class Building
{
      String address = "1234 Main St";
}



public class Skyscraper extends Building
{
      int topFL = 102;
}




Is the following statement correct in java?


      Skyscraper  myFavorite = new Building();


True
Correct Response
False
Question 24

2 / 2 points






Consider the following java classes ( Building and Skyscraper):




public class Building
{
      String address = "1234 Main St";
}



public class Skyscraper extends Building
{
      int topFL = 103;
}




Is the following statement correct in java?


      Skyscraper  tinySmallHouse = new Skyscraper();

Correct Response
True

False
Question 25

4 / 4 points






Given the following class definition, which of the following are considered part of the class's public interface?
public class CashRegister

{

public static final double DIME_VALUE = 0.1;

private static int objectCounter;

public void updateDimes(int dimes) {…}

private boolean updateCounter(int counter) {…}

}


DIME_VALUE and objectCounter

objectCounter and updateCounter
Correct Response
DIME_VALUE and updateDimes

updateDimes and updateCounter
Question 26

2 / 2 points






A(n)
___class___Correct Response
should represent a single concept from the problem domain, such as business, science, or mathematics.
Question 27

2 / 2 points
The CustomerAccount as discussed in our class is an immutable class.

True
Correct Response
False
Question 28

2 / 2 points






Math is an immutable class.
Correct Response
True

False
Question 29

4 / 4 points






A static method can have which of the following types of parameters?

Both implicit and explicit parameters.
Correct Response
Only explicit parameters.

Only implicit parameters.

A static method cannot have parameters.
Question 30

2 / 2 points






An input into a parameter of type double can potentially be changed by a Java method.

True
Correct Response
False
Question 31

2 / 2 points






A parameter of type LoyalCustomerAccount (as discussed in class) can potentially be changed by a Java method.
Correct Response
True

False
Question 32

2 / 2 points






If you do not include a package statement at the top of your class source file, its classes will be placed in which package?
Correct Response
the default package, which has no name

java.lang

java.awt

java.util
Question 33

4 / 4 points






Choose the valid packages from the Java Platform:

Correct Response
javax.swing

Correct Response
java.util (utility)

Correct Response
java.system

Correct Response
java.lang.Math
Question 34

4 / 4 points







Take your favorite Product.java class from our lab practices,
sketch an .toSting() method to overide the default print output.
public class Product
{
public String name;
public String serialN;
public double price;

public override String ToString()
{
return price + " " + serailN + " " + " " + name;

}
}
The correct answer is not displayed for Long Answer type questions.
Question 35

2 / 2 points
Related classes in the standard library are organized into
___packages___Correct Response
.
Question 36

4 / 10 points
Sketch java codes to implement a Comparable<T> interface inside a Product.java class such that the products could be ranked by serial #s.
Then override the .toString() method inside the Product.java class to printout the product object reference, the product serial#, and the product name.
public class Product
{
public String name;
public String serialN;

public override String ToString()
{
return serialN + " " +name;

}
}
The correct answer is not displayed for Long Answer type questions.

No comments:

Post a Comment