100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4.2 TrustPilot
logo-home
Tentamen (uitwerkingen)

CMSC132 Exam #1 Questions With 100% Correct Answers 2024

Beoordeling
-
Verkocht
-
Pagina's
8
Cijfer
A+
Geüpload op
03-07-2024
Geschreven in
2023/2024

Classes can only extend more than one other class if at least one of those classes is an abstract class. - ANSFalse - a Class can never extend more than one class. Downcasting can be done implicitly. - ANSFalse - it must be done explicitly or your code will not compile. "Sideways" casting is never allowed - ANSTrue '' will refer to the current object, treating it as an instance of the parent of the parent of the current class. - ANSTrue. For example, if class C extends class B, which extends class A, then calling "String()" from within class C will return the result of A's toString method. Constructors in subclasses must directly invoke the constructors of every single parent class before initializing the instance variables unique to that subclass. - ANSFalse - usually, a single call to the constructor of the immediate superclass is needed, however. This is done with the keyword 'super' and must be the first line in the constructor. . Assume there is a method named foo in a superclass A, which has been overridden in B (a subclass of A). If () is called from within class B, it will run the foo() method from class A, but if foo() is called from within class B, it will run the foo() method from class B. - ANSTrue Every class is a subclass of Object. - ANSTrue - note that this question doesn't necessarily mean that the class is ONLY a subclass of Object, but every class does inherit from Object, either directly or indirectly. When you override a method, you are allowed to change the number of arguments. - ANSFalse - the method signature must be exactly the same When you overload a method, you are allowed to change the number of arguments. - ANSTrue To sort an ArrayList of MyObject objects using C, MyObject must have an implementation of the compareTo method defined in the class. - ANSFalse - you can also pass in a Comparator with the compare method. Unchecked exceptions are generally for common exceptions that need to be accounted for. - ANSFalse - this is describing checked exceptions, not unchecked exceptions. An abstract class must include at least one abstract method. - ANSFalse An abstract class can contain instance variables and constructors. - ANSTrue You can implement more than one abstract class. - ANSFalse - You can EXTEND only one abstract class. An abstract class can be instantiated. - ANSFalse An interface can be instantiated. - ANSFalse A Java class can implement multiple interfaces. - ANSTrue Many Java classes can extend the same superclass. - ANSTrue - however, a single Java class cannot extend multiple superclasses. Make sure you understand this distinction. Many classes can implement the same interface. - ANSTrue Public constructors can be declared in interfaces. - ANSFalse Explicit upcasts can sometimes cause a ClassCastException to be thrown. - ANSFalse. Explicit upcasts are never a problem, and because of this, it's not even necessary to make them explicit - the Java compiler will do it for you implicitly. Explicit downcasts can sometimes cause a ClassCastException to be thrown, however. Java enums can be used with switch statements - ANSTrue Calling the values() method on an enum type will return an ArrayList of the enum's possible values - ANSFalse - it will return an Array, not an ArrayList. Assume we have access to an enum called Day that has the values SUN, MON, TUE, etc. The following statement will run successfully: Sln("Day: " + Day.MON ); - ANSTrue Fields inside a static nested class cannot be accessed by their outer class. - ANSFalse - privacy is not respected between the two classes Every inner class object must be connected to an outer class object - ANSTrue String[] is a subtype of Object[] - ANSTrue ArrayList<String> is a subtype of ArrayList<Object> - ANSFalse public class Container { ... } If MyObject is an interface, the program will not compile - ANSFalse public class Container { ... } If MyObject is a class then MyObject cannot be passed in for T - ANSFalse - MyObject or any subtype of MyObject can be used as the generic type for this class. The following method will compile but throw an exception at runtime (assuming the existence of the Food class). public void someMethod (ArrayList foodList <? extends Food> foodList) { foodL(new Food()); } - ANSFalse - it won't even compile. A collection cannot be added to if its generic type uses the ? extends operator. Putting final before a method means it cannot be overloaded - ANSFalse - it means that the method cannot be overridden Suppose the following declaration and instantiation is made: final int x = 8; Given this declaration, the following code fragment will NOT compile, but will throw an exception at runtime: int y = 21; x = (y + 7) / 4; - ANSFalse - it will not compile. Putting final before a method means any instance variable instantiated within it cannot have their value modified. - ANSFalse - it means that the method cannot be overridden. A class that has been declared final cannot have any subclasses. - ANSTrue Your friend is writing a name comparator for the Dog class, but is having some trouble. Here is the code for the comparator: public class DogNameComparator implements Comparator { public int compare(Dog other) { return Name().compareTo(Name()); } } Assuming that the Dog class has a getName method, what is the problem with the comparator shown above? - ANSThere is no current object "this", and the compare method is supposed to take two parameters. It looks like your friend got a bit confused between the compare() method and the compareTo() method. Here's what the correct implementation would look like: public int compare(Dog one, Dog two) { return Name().compareTo(Name()); } a. for (int i = 0; i < n; i++) { for (int j = i; j > n; j++) { Sln("hello world"); } } - ANSThe time complexity is actually O(n) here because the inner loop never runs. Notice that the inner loop begins at j = i, and its condition is j > n. However, if you look at the outer loop header, you can see that i will never be greater than n, so the condition j > n will never be satisfied. for (int i = 1; i < n; i*=2) { for (int j = i; j < n; j++) { Sln("hello world"); } } - ANSThe time complexity in this example is actually O(n*log(n)). While the outer loop depends on n, it depends logarithmically on n, not linearly. The inner loop depends linearly on n. Together, these two facts yield an asymptotic complexity of O(n*log(n)) for (int i = 0; i < n; i++) { S("hello"); } for (int j = 0; j < n; j++) { S("world"); } - ANSThe time complexity in this example is just O(n). While both loops depend linearly on n, they are not nested loops. Since they run completely independently of one another, we should add their individual time co

Meer zien Lees minder
Instelling
CMSC 132
Vak
CMSC 132









Oeps! We kunnen je document nu niet laden. Probeer het nog eens of neem contact op met support.

Geschreven voor

Instelling
CMSC 132
Vak
CMSC 132

Documentinformatie

Geüpload op
3 juli 2024
Aantal pagina's
8
Geschreven in
2023/2024
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

$10.79
Krijg toegang tot het volledige document:

100% tevredenheidsgarantie
Direct beschikbaar na je betaling
Lees online óf als PDF
Geen vaste maandelijkse kosten

Maak kennis met de verkoper
Seller avatar
Kiranga
5.0
(1)

Maak kennis met de verkoper

Seller avatar
Kiranga John Hopkins University
Bekijk profiel
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
1
Lid sinds
1 jaar
Aantal volgers
0
Documenten
122
Laatst verkocht
1 jaar geleden

Here we offer revised study materials to elevate your educational outcomes. We have verified learning materials (Research, Exams Questions and answers, Assignments, notes etc) for different courses guaranteed to boost your academic results. We are dedicated to offering you the best services and you are encouraged to inquire further assistance from our end if need be. Having a wide knowledge in Nursing, trust us to take care of your Academic materials and your remaining duty will just be to Excel. Remember to give us a review, it is key for us to understand our clients satisfaction. We highly appreciate refferals given to us. Also clients who always come back for more of the study content we offer are extremely valued. All the best

Lees meer Lees minder
5.0

1 beoordelingen

5
1
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via Bancontact, iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo eenvoudig kan het zijn.”

Alisha Student

Veelgestelde vragen