1/103
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
what is the difference between method overloading and method overriding in Java?
method overloading means having the same method name but different parameters, while method overriding means a subclass changes a method that it inherits from its superclass
what is the purpose of the final keyword in Java?
means that a variable’s value, a method’s behaviour, and a class’ inheritance cannot be changed
what is the difference between a checked exception and an unchecked exception
checked exceptions must be caught with try-catch or declared in the method, but unchecked exceptions happen during the program and don’t have to be handled explicitly
what is the difference between a constructor and a method in Java?
a constructor initializes a new object, while a method performs actions on an object
what does the this keyword do in a constructor or method?
refers to the current instance of the class
what is the purpose of the super keyword in java?
refers to the superclass and is used to call parent class methods or constructors
explain the difference between == and equals() in Java
one checks if two objects are the exact same thing in memory, while the other checks if their contents or values are the same
what is the difference between a static method and a non-static method
one belongs to the class while the other belongs to an instance of the class
what is a final variable, and how is it different from a regular variable?
a final variable cannot be changed once assigned, whereas a regular variable can be changed
how does the try-catch block work in exception handling?
the try block contains code that might throw an exception, and the catch block handles the exception if it occurs
what is the purpose of throw and throws keywords in Java exceptions?
throw is used to cause an exception right away, while throws tells that a method might cause an exception
what is the difference between String and StringBuilder in Java?
String is immutable while StringBuilder is not mutable
what is polymorphism and how is it used in Java?
it lets different kinds of objects be used like they are the same type, usually by replacing methods with new versions
what is an abstract class in Java?
is a class you can’t make objects from, but other classes can inherit from it
what is the difference between an interface and an abstract class in Java?
an interface is a list of method names without code that any class can use, an abstract class can have methods with or without code and other classes can extend it
what is a constructor overloading in Java?
occurs when multiple constructors with different parameters are defined in a class
what does instanceof operator do in Java?
checks if an object is of a certain type, it verifies the object’s class when the program is being ran
what is the purpose of the private access modifier in Java?
restricts access to a field or method to within the same class only
what is the null keyword in Java?
represents the absence of a value or reference for a variable
what is the purpose of the continue statement in Java?
skips the current iteration of a loop and moves to the next iteration
what is the difference between ArrayList and LinkedList?
ArrayList stores items in a growable array and lets you quickly get any item, while LinkedList stores items in a chain and lets you add or remove items faster
what does the default keyword do in an interface?
lets a method in an interface have a default code that classes can use or override
what is method chaining?
lets you call methods one after another on the same object in one line, because each method returns the object itself
what is the difference between ArrayList and HashSet?
ArrayList lets you use store methods in an ordered list, because it keeps insertion order, while HashSet stores unique elements in no order because it does not allow duplicates
what is the purpose of the static keyword?
lets you use methods or variables without creating an object, because it belongs to the class itself
what is the difference between a method signature and a method declaration?
method signature includes the name and parameters, because it identifies the method while the method declaration includes the return type an access modifiers, because it defines the method
what is the purpose of the default constructor?
creates an object without setting any values because it is automatically provided if no constructor is given
what is the difference between Thread.sleep() and wait()?
thread.sleep() pauses the thread for a certain time, while wait() pauses it until another thread tells it to continue
what does super() do in a constructor?
calls the parent class constructor, because it ensures the parent class is properly set up
what is the purpose of the final keyword in method parameters?
lets you make sure a parameter’s value cannot be changed, prevents reassignment
what does the this keyword do in a constructor?
refers to the current object, because it helps distinguish instance variables from parameters
what is a hashcode?
uniquely identifies objects because it helps quickly locate and compare objects in hash-based collections
the major difference between stack memory and heap memory is that the stack is used to store the order of method execution and local variables while the heap memory stores the objects and it uses dynamic memory allocation and deallocation
true or false
true
in java, the default value for a class variable of type int
is -1.
true or false
false
instance variables are used to represent an object’s state
true or false
true
subclasses can access private instance variables of the superclass
true or false
false
when writing regression tests, it is ok to directly interact with private variables
true or false
false
a uml use case diagram is considered a behavioural diagram, as opposed to a structural diagram
true or false
true
in java, the toString() method automatically collects a class’ attributes and generated a formatted string representation of the class
true or false
false
you need to provide the size of an arrayList when you are creatin the arrayList
true or false
false
polymorphism can be used with both inherit super types and implemented supertypes
true or false
true
which of the following is not a class found in java’s collection framework
a) arraylist
b) hashmap
c) hashset
d) dictionary
dictionary
which of the following are not important for a regression test program?
a) constructing objects are calling methods
b) displaing the results of the method calls
c) displaying the values that you expect to get
d) reading input from the user
reading input from the user
suppose the class coffee extends the class drink. which one of the following assignments is legal?
drink x = new drink();
coffee y = new coffee();
a) y = x;
b) x = y;
c) y = new drink();
d) new drink() = new coffee();
x = y;
suppose you are to design an inheritance hierarchy with the following classes: mouse, cat, mammal, and tiger. which of these is the superclass?
a) tiger
b) mammal
c) mouse
d) cat
mammal
which programming technique should be used if you want a method to have different behaviour depending on the class of the object that is invoking it?
a) polymorphism
b) the instaceof operator
c) an if-else statement
d) the getclass method
polymorphism
which of the following java
snippets would be used to declare a hashmap
that contains items of type exam
and is accessed by a key of type string
?
a. hashmap<exam> exams = new hashmap<string>();
b. hashmap<t> exams = new hashmap<t>();
c. map<exam, string> exams = new hashmap<exam, string>();
d. map<string, exam> exams = new hashmap<string, exam>();
d
when should you delete your testing code from a class?'
a) if it is a simple class you don’t need to write proper regression tests
b) when all tests are passed and you know the class wont be changing
c) your regression tests should never be deleted
d) after several months without errors it makes sense to delete your tests to make your code easier to read
your regression tests should never be deleted
consider the following code fragment:
Object obj = “CMPT 270”;
System.out.println(ob.length());
which of the following statements are true?
a) the code compiles are runs without issue
b) the code will not compile because the Object class does not have a method called length()
c) the code will not compile because a String object cannot be assigned to something of type object
d) the code will compile but throw an exception
the code will not compile because the Object class does not have a method called length()
software development is all about learning a programming language
false
object oriented programming
a program consisting of classes and objects organized to manage the complexity of large-scale systems
procedural programming
a program consisting of methods/functions calling each other
method
implements behaviors relevant to the purpose of the system
field or attribute
stores data relevant to the purpose of the system
container object
data structure to store entities
entity object
model of a real-world thing in an application
interface object
facilitates communication between the system and the outside world
control object
organizes computation or flow of the program
a uml class diagram is a behavioral diagram
true or false
false
given 3 classes: plant, tree, flower, which of the following best describes their relationship to one another
inheritance
suppose you have 2 classes: house, and wall, where the house is a container of wall objects. which of the following best describes this relationship?
composition
suppose you have 2 classes: book, and bookshelf. which of the following best describes the relationship between these 2 classes?
aggregation
suppose you have 2 classes: hammer and nail, which of the following best describes the relationship between these 2 classes
association
which principle should be used if you want a method to have different behaviour depending on the specific class the method is being invoked on
polymorphism
which of the following statements describes an inheritance relationship?
a textbook is a book
interfaces and inheritance are different name’s for the same concept
true or false
false
using uml class diagrams you can express relationships between two classes. which of the following cannot be expresed in a uml diagram?
polymorphism
encapsulation
grouping related variables and functions together to reduce complexity and increase reusability
polymorphism
refactor ugly if and switch / case statements
inheritance
eliminate redundant code
abstraction
hide details and shows the essentials; isolate the impact of changes
which of the following data types is not a primitive data type in Java
a) string
b) double
c) boolean
d) int
string
all data types in java are references to data allocated on the heap
true or false
false
if you wanted to store measurement data, which Java data type is recommended?
double
Just like in Python, single quotes (' ') and double quotes (" ") are both used to denote a String literal.
true or false
false
Which of the following for loops is correct syntax in Java?
for(int i=0; i<10; i++);
{
System.out.println("Hello");
}
for(int i=0; i<10; i++)
{
System.out.println("Hello");
}
for(int i in Range(10))
{
System.out.println("Hello");
}
for(int i=0, i<10, i++)
{
System.out.println("Hello");
}
for(int i=0; i<10; i++)
{
System.out.println("Hello");
}
What would be the output from the following code snippet?
int x = 10;
int y = 4;
if(x >= 10)
{
System.out.println(x/y);
}
else
{
System.out.println(y/x);
}
a) 2
b) 2.5
c) 0.4
d) 0
2
Assume you have the following String declarations. Which of the following expressions evaluate to true? (select all that apply)
String s1 = "Hello";
String salutation = "Hi";
String howdy = "hELLo";
String greeting = new String("Hello");
a) s1.equals(howdy);
b) s1.equals(greeting);
c) s1 == greeting
d) s1.equalsIgnoreCase(howdy);
e) s1.compareTo(salutation);
s1.equals(greeting); s1.equalsIgnoreCase(howdy);
what does a toString() method do in Java?
it allows a programmer to define a String representation of their class
the tree class does not have an explicit ‘chopDown’ method. which of the following describe the chopDown functionality in the system
a) the Tree object's height is set to 0
b) the Tree object has a boolean variable named 'isDead', which is set to true
c) the Tree object's memory is manually deallocated using free()
d) the Tree variable is set to null
the Tree variable is set to null
why doesn’t the Tree class have a setter/mutator to set the height attribute?
a) it does have one, the method grow() acts as a mutator
b) it doesn't need one, because the height attribute is public so any class can change it directly
c) it does have one, the method getHeight() also sets the height attribute
d) it doesn't need one, because the height attribute should never change
it does have one, the method grow() acts as a mutator
which class acts as the main/client program
a) treePlanter
b) inventory
c) forest
d) tree
treePlanter
the lecture followed a specific development process. Which of the following steps was omitted from the lecture (for now)?
a) Implementing/coding methods
b) UML
c) JUnit Testing
d) Creating stub classes/methods
e) Documentation
JUnit Testing
in the development process followed in the lecture, which of the following steps was last?
a) Creating stub class/methods
b) Implementing/coding methods
c) UML
d) Unit Testing
e) Documentation
Implementing/coding methods
debugging
inferring the cause of undesired behavior or incorrect results
fault
your program exhibits behaviour that is not intended / an undesired behaviour or incorrect result
error
the “thing” that causes a fault / the cause of an undesired behaviour or incorrect result
validation
any method to increase confidence in the correctness of a software system
failure
inability of the system to do what is required
coverage
how much of the code is tested
manual testing
a human types some input to a program
automated testing
the computer runs a script performing the tests
which of the following statements about the relationship between errors and faults is FALSE?
a) it's possible for one error to produce multiple faults
b) if there is no error in the code, there are no faults
c) it's possible for code to have an error but produce no faults
d) it's possible for a fault to be observed, but no error to cause it
it's possible for a fault to be observed, but no error to cause it
when should you delete your testing code from a class?
your regression tests should never be deleted
For CMPT 270, where will you be writing your unit tests?
In the static main method of the class being tested
when writing regression tests, we should print the status of each test to the console.
true or false
false
using the inheritance structuer discussed in the lecture, assume you have a container of type Water Monster. Which of the following types could be stored inside the container?
a) squiiirtle
b) starfishy
c) peekatu
d) monster
e) electric monster
f) water monster
squiirtle, starfisgy, water monster
effective use of polymorphism is good because it increases coupling in a software system
true or false
false
which keyword is used to indicate inheritance in java?
extends
polymorphism can be used with both inherited super types and implented interface types
true