Busy. Please wait.
Log in with Clever
or

show password
Forgot Password?

Don't have an account?  Sign up 
Sign up using Clever
or

Username is available taken
show password


Make sure to remember your password. If you forget it there is no way for StudyStack to send you a reset link. You would need to create a new account.
Your email address is only used to allow you to reset your password. See our Privacy Policy and Terms of Service.


Already a StudyStack user? Log In

Reset Password
Enter the associated with your account, and we'll email you a link to reset your password.

Question and answers

Quiz yourself by thinking what should be in each of the black spaces below before clicking on it to display the answer.
        Help!  

Question
Answer
Advantages of subclassing (7)   - reduce complexity - make use of work already done in implementing - save work -- involved in redesigning and rewriting program code -- when modifications are needed - reduce amount of testing needed - minimise the likelihood of errors  
🗑
public String toString() Explain 1. public 2. String] 3. toString 4. ()   1. public is the access modifier that specifies which other classes have access to the method 2. String is the return type of the method 3. toString is the name of the method 4. () delimits the argument list, which is empty in this case  
🗑
Advantages of using super (2)   1. Reduces the likelihood of errors that could result from rewriting code already implemented, by reusing behaviour from the superclass 2. If the superclass code were to be changed, no changes have to be made in the code of the subclass  
🗑
Syntactic difference between message and variable   message: Parantheses "()" after the name variable: not  
🗑
difference of "this" and "super"   Both reference the receiver. But "super" results in accessing of members of the superclass of the receiver in which it appears  
🗑
Class header for defining public class ClassX as a direct subclass of an existing class, ClassY   public class ClassX extends ClassY  
🗑
Order of class declaration (by convention)   - import - class variables - instance variables - constructors - methods  
🗑
@Override - advantage of use   The annotation @Override checks that the method is an override. Causes a compile error if the method is not found in one of the parent classes or implemented interfaces.  
🗑
ClassA and ClassB contain a method doSome() ClassB @Override pubic void doSome() { super.doSome(); } myB, is sent the message doSome(). Which object(s) do super and this reference at runtime?   They both reference the receiver of the doSome() message - namely the object referenced by myB (an instance of Class B)  
🗑
ClassA and ClassB contain a method doSome() ClassB @Override pubic void doSome() { super.doSome(); } myB, is sent the message doSome(). When the code is executed, in which class would the JVM start looking for the method?   It wold start looking for the method doSome() in ClassA, the superclass of the class in which super.doSome() appeared. If there were no method doSome() in ClassA, the JVM would look in the superclass of ClassA, and so on up the class hierarchy.  
🗑
ClassA and ClassB contain a method doSome() ClassB @Override pubic void doSome() { super.doSome(); this.doElse(); } myB, is sent the message doSome(). When this.doElse() is executed, in which class would the JVM start looking?   It would start looking in ClassB, the class of the receiver. If no such method existed in ClassB, it would look in the definition of ClassA, and so on up the class hierarchy.  
🗑
In a system, resource such as text files, folders and programs understand the message open(), although these objects are instances of different classes and each behaves in a different way in response. What word is used to describe this kind of situation?   The message open() is polymorphic with respect to instances of the (hypothetical) classes TextFile, Folder and Program.  
🗑
Explain the word polymorphism.   A polymorphic message is a message understood by more than one class. Each class of object can behave in its own way in response to such a message. = same message, different interpretation  
🗑
Explain the word polymorphism, using position() from the Frog and HoverFrog classes as an illustration.   All instances of the class Frog interpret the message home() by setting their position to 1, whereas instances of the class HoverFrog set their position to 1 and their height to 0.  
🗑
Explain the word polymorphism, using toString() from the Frog and HoverFrog classes as an illustration.   The message toString() is understood by instances of both classes. The behaviour caused by sending toString() to a frog is different from that produced by sending the same message to a hoverfrog.  
🗑
Which access modifier provides direct access to class members 1. within a defining class 2. via direct/inidrect inheritance 3. via a reference to an object of the class   1. public, protected, default, private 2. public, protected, default (if in the same package 3. public, protected (in in the same package), default (if in the same package)  
🗑
What is the scope for the different access levels of class members (methods and variables) and classes?   1. Within the defining class - (all) 2. Via inheritance - public - protected - default (if in the same package) 3. Via a reference to an object of the class - public - protected (if in the same package) - default (if in the same package)  
🗑
Benefits of access modifiers   They support data hiding and prevent accidental or intentional misuse of private members of a class  
🗑
Terminology regarding 1. instance method 2. class method 3. constructor   1 The message doSomething() is sent to the object referenced byh myVar 2 The message doSomething() is invoked on the class SomeClass 3 Calling a constructor (reflects that there is no object to which a message can be sent when a constructor is used)  
🗑
Difference constructor / method   - no overriding - direct access to instance variables (no accessors) - no return type - same name as class (but: also allowed for methods) - starts with uppercase letter - calls the constructor of the superclass (method can only send a message to it)  
🗑
Purposes of super   super in a method body represents the receiver of the message which follows it -> super.home() calls the constructor from the direct superclass of the class being defined for initialising the superclass's instance variables -> super([arg1, arg2])  
🗑
What are the default values when variables / objects are not initialised by the programmer?   primitive types: - boolean: false - numeric: 0 or 0.0 - chars: character with integer value 0 reference types: null constructor: zero formal arguments. Simply executes super() -> instance variables are set to the default values of their types  
🗑
Process of defining a subclass   1. Keyword extends in class header 2. Declare instance variables 3. Declare constructor(s) 4. Define new methods 5. Override methods in the superclass. These methods may invoke the method from the superclass, using super 6. Javadoc comments  
🗑
Syntax of reusing constructor code within a class   The keyword this can be used to pass arguments to an existing constructor within the class // constructor 1 public Const() { super(); this.var = ""; } // constructor 2 public Const() { this(""); }  
🗑
Criteria whether a new class should be implemented as a subclass of an existing class   Needs to have a is-a relationship  
🗑
Advantages of abstract classes   Avoids duplicating code implementing common behaviour. E.g for classes which have a lot in common but neither is an appropriate subclass of the other (e.g. frogs and toads)  
🗑
Explain: An abstract class cannot be instantiated   One cannot construct an instance of an abstract class, even if it has (a) constructor(s) containing explicit initialisation code. In order to create an object a concrete (non-abstract) class has to be used  
🗑
Difference between variables and objects (Java designer slogan)   "variables have types, objects have classes." Variables: declared at compile time Objects: created at run time  
🗑


   

Review the information in the table. When you are ready to quiz yourself you can hide individual columns or the entire table. Then you can click on the empty cells to reveal the answer. Try to recall what will be displayed before clicking the empty cell.
 
To hide a column, click on the column name.
 
To hide the entire table, click on the "Hide All" button.
 
You may also shuffle the rows of the table by clicking on the "Shuffle" button.
 
Or sort by any of the columns using the down arrow next to any column heading.
If you know all the data on any row, you can temporarily remove it by tapping the trash can to the right of the row.

 
Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.

  Normal Size     Small Size show me how
Created by: gabimuc
Popular Computers sets