Java Interview Test

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

What is the Output for the below program?

import java.util.*;

public class Company {


private final String first, last;

public Company(String first, String last) {


this.first = first;
this.last = last;
}

public boolean equals(Object o) {


if (!(o instanceof Company))
return false;
Company n = (Company) o;
return n.first.equals(first) && n.last.equals(last);
}

public static void main(String[] args) {


Set<Company> s = new HashSet<Company>();
s.add(new Company("Tibco", "Software"));
System.out.println(s.contains(new Company("Tibco",
"Software")));
}
}
What is the output for the below program?

public class Super {


public Super() {
overrideMe();
}

public void overrideMe() {


}
}

import java.util.Date;

public final class Sub extends Super {


private final Date date;

Sub() {
date = new Date();
}

@Override
public void overrideMe() {
System.out.println(date);
}

public static void main(String[] args) {


Sub sub = new Sub();
System.out.println("date");
sub.overrideMe();
}
}

You might also like