SWEN 20003 - OO Software Development
7 flashcards · Other · by kgashok
public class YourClassNameHere { public static void increment(int input) { input = input + 1; } public static void main(String[] args) { int a = 0; increment(a); System.out.println(a); } } What will the output?
0 This is because pass by value does not change the value of a.
public class YourClassNameHere { public static int increment(int input) { input = input + 1; return input; } public static void main(String[] args) { int a = 0; a = increment(a); System.out.println(a); } } What will be the output?
1 This is because we made the function return the incremented value and updated a in the original scope.
What are the three common relationships that are common between classes?
Aggregation (has-A) Inheritance (is-A) Dependence (uses-A) AID - aggregation, inheritance and dependence.
Give examples of is-A and has-A relationships.
In addition to is-A and has-A relationships, there is a third one. What is it?
uses-A relationship In Java, the relationship is established using the keyword "implements"
Give an example of a uses-A relationship .
class Channel{ private String name; private Map<Integer,Show> showList; public Channel(String name){ this.name = name; showList = new HashMap<>(); } public int getShowTime(String showName){ int showTime = 0; return showTime; } public String getShowName(int showTime){ String showName = ""; return showName; } } class Show { private String name; private int airTime; public Show(String name, int airTime){ this.name = name; this.airTime = airTime; } }