Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Code Review “Invoice.

java”
package interview;

import java.sql.Date;

public class Invoice {


Date date;
double amount;
String description;
String currency;

public Invoice(Date dateCreated, Double amount, String currenyName, String text) {


date = dateCreated;
description = text;
amount = amount;
currency = currenyName;
}

public double getAmount() {


return amount;
}

public String getDescription() {


return description;
}

public Date getDate() {


return date;
}

public String getCurrency() {


return currency;
}

public String toString() {


return date.toString() + ": " + amount + " " + currency + " " + description;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof Invoice)) {
return false;
} else {
Invoice other = (Invoice) obj;
return date == other.date
&& description == other.description
&& amount == other.amount
&& currency == other.currency;

}
}
}
Single Choice Questions

1. Which of the following below live on the heap in java?


● Class
● Instance variable
● Method
● Object

2. Which of these interfaces handle sequences?


● Set
● List
● Comparator
● Collection

3. Which statement about a valid .java file is true?


● It can only contain one class declaration.
● It can contain one public class declaration and one public interface
definition.
● It must define at least one public class.
● It may define at most one public class.

4. Which is correct about an instance variable of type String?


● It defaults to an empty string.
● It defaults to null.
● It does not have a default value.
● It will not compile without initializing on the declaration line

5. How do you force garbage collection to occur at a certain point?


● Call System.forceGc()
● Call System.gc()
● Call System.requireGc()
● None of the above

6. What is the output of the following program?


public class Test {

private static int one = 10;

int two = 20;

public static void main(String []args) {

Test test = new Test();

int today = 20; two = 40;

System.out.println(today + test.two + test.one);

7. What is the value of total after executing the following code snippet?

int meal = 5;

int tip = 2;

int total = meal + (meal>6 ? ++tip : --tip);

● 1
● 2
● 3
● 6
Preparation for Interactive Part/Discussion

1. What is Deadlock?
2. How do you stop a thread in java?
3. What is the difference between the Thread class and Runnable
interface for creating a Thread?
4. What is a race condition?
5. What are Generics? What are the benefits of Generics?
6. What is the difference between Comparable and Comparator
interface?
7. What is the difference between HashSet and HashMap?

You might also like