Friday, 24 August 2018

JP Morgan Written Test

JP Morgan Java & SQL Online Screening

Q1 Suppose there is a class called Employee. Is it possible to create a Map as shown below?
Map<Employee, String> map = new HashMap<Employee, String>();

if yes, what minimum change will you make to the Employee class (Pre - java 8)

A. It is not possible to create a map this way
B. Override equals method
C. Override hashcode method
D. Override compareTo method
E. Override equals and hashCode method


Q2 Suppose there is a class called Employee. Is it possible to create a Map as shown below?

Map<Employee, String> map = new TreeMap<Employee, String>();

if yes, what minimum change will you make to the Employee class

A. It is not possible to create a map this way
B. Override equals method
C. Override hashcode method
D. Override compareTo method
E. Override equals and hashCode method

Q3 Given the following piece of code, which of the following options will never be printed by this program


public class SynchronizedTest {
    private String name;

    public SynchronizedTest(String name) {
        this.name = name;
    }

    public static synchronized void staticSynchMethod() {
        System.out.print("SM1 ");
        System.out.print("SM2 ");
    }

    public synchronized void synchMethod() {
        System.out.print(name + "M1 ");
        System.out.print(name + "M2 ");
    }

    public static void main(String[] args) throws InterruptedException {
        final SynchronizedTest o1 = new SynchronizedTest("o1");
        Thread t1 = new Thread() {
            @Override
            public void run() {
                o1.synchMethod();
            }
        };

        Thread t2 = new Thread() {
            @Override
            public void run() {
                staticSynchMethod();
            }
        };

        Thread t3 = new Thread() {
            @Override
            public void run() {
                staticSynchMethod();
            }
        };

        t1.start();
        t2.start();
        t3.start();
        t1.join();
        t2.join();
        t3.join();
    }
}

A. O1M1 O1M2 SM1 SM2 SM1 SM2
B. O1M1 SM1 SM2 O1M2 SM1 SM2
C. SM1 SM2 O1M1 O1M2 SM1 SM2
D. SM1 SM1 SM2 SM2 O1M1 O1M2
E. SM1 O1M1 SM2 O1M2 SM1 SM2

Q4 Which of the class given below relies upon its subclasses for complete implementation of its methods?
A. Object class
B. abstract class
C. Class class
D. None of these

Q5 In Java, the methods declared as ____________ cannot be overridden.
A. public, static or abstract
B. public or final
C. private, static or final
D. abstract or final

Q6 How many join conditions are required to join 4 tables in SQL?
A. 1
B. 2
C. 3
D. 4

Q7 Which of the following commands is used to remove an index from the database in SQL?
A. Delete Index
B. Drop Index
C. Remove Index
D. Roll back index

Q8 Which of these is not a type of SQL constraint?
A. Primary Key
B. Foreign Key
C. Alternate Key
D. Unique

Q9 In SQL, which of the following statements is used to end the current transaction and make permanent changes in the transaction.
A. ZIP
B. PACK
C. COMMIT
D. SAVE

Q10 Consider below table Employee
Field
id - int
name - text
manager_id - int

Write a SQL query to list all employee names along with their manager names, output should include employee without any manager as well.


select a.name, b.name from Employee a left join Employee b where a.manager_id = b.id;


Q11 For above table, Write a SQL query to list all manager ids and names who have more than 1 report.


Q12 Given weights of a log from left end upto distance x upto length l. Write a function that returns the balance point from the left.

No comments :

Post a Comment