Citigroup Interview Question for Developer Program Engineers


Country: United States
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
0
of 0 vote

can we use try/catch to implement the stale object?

- Jess May 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is it some kind of runtime exception that's getting thrown? In such a case the method call will not be executed at all.
Wonder what's the real intent of the question.

- EK MACHCHAR May 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Exception occurs in constructor initialization itself and since the object creation failed, it wont proceed to method call. it can be Exception or RuntimeException. Below is the code

public class C {
	A a;
	B b;
	public C() throws Exception{
		//Doin initialisation to perform some DB connection
		a= new A();
		b= new B();
		throw new RuntimeException("Error occured");
	}
	void displaC(){
		a.displayArea();
		b.displayArea();
		System.out.println("display Area C");
	}
	public static void main(String[] args) throws Exception {

	    C a= new C();
	    a.displaC();
    }
}

- Dhana June 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

??? your code makes no sense?

The question is how would you handle the case where the DB connection fails to be made. Typically what you would do is the following.

1) In the constructor you would use try/catch block to handle the exception. Set the DB connection to null.
2) In each method of the class put a guard in that checks if the DB connection = null. If so then throw an exception or give some other indication that the DB connection is not valid.
2)

- Anonymous October 30, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Sorry, hit the submit button early.

The point being that the calling class should not know anything about the internals of the class which is maintaining the DB connection.

If you let the RuntimeException propagate upwards then yes the method call will not be made, but this would be considered sloppy programming.

- Anonymous October 30, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

use static method and call the method through class name
so, the code will be A.amethod();

- Anonymous December 01, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More