SAS Research Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

Here is the trick, overriding equals have the signature which take Object as argument. so without overriding just implement a new method called equals which takes argument of type Test (note that you are not overriding equals from java specification but implementing a new equals )

public class Test{
	public boolean equals(Test obj) {
		return false;
	}
}

note override equals has the below signature (see the argument)

@Override
	public boolean equals(Object obj)

- Yogesh Bhardwaj June 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I have tried hard to figure out answer.. but couldn't find any.. even if override hashcode it will be the same for same object

- kinshu August 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

:-) Feeling is mutual dude.

- Arun Manivannan August 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about this...?


Class A{
TestA testObj = new TestA();
System.out.println(testObj.equals(testObj = null));
}

- Ijlal Ahmad September 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class EqualsTest{

public boolean equals(EqualsTest a)
{
if (this==a)
{
return true;
}

return false;

}
public static void main(String args[])
{

EqualsTest a =new EqualsTest();
EqualsTest b= new EqualsTest();

System.out.println(a.equals(a));


}

}


This code is not overriding as needed in program, instead is doing overloading

- ankijava September 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Here is the simple answer:

class TestA {
public boolean equals(Test1 t) {
return false;
}
}

Override the equals method in the new class which always return false.

- madhusudhan.sb September 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Read the condition: ***NOTE: You cannot override equals method***

- Kuldeep September 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Class A{
TestA testObj = new TestA();
System.out.println((!(testObj.equals(testObj))));
}

- deb September 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think that in Java you have Float.NaN (Not a Number). If you compare it to anything it'll return false (even for another NaN)

- avico81 October 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It could be done with small hack in println of Printstram :)

import java.io.PrintStream;

public class Program {
    static {
       
        PrintStream ps = System.out;
        System.setOut(new PrintStream(ps){
            public void println(boolean x) {
                synchronized (this) {
                    super.println(!x);
                }
            }
        });
    }

    public static void main(String args[]) {
         
            TestA testObj = new TestA(); 
            System.out.println(testObj.equals(testObj)); 
        
    }
    
}
class TestA {
   
}

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

Something I have in mind is like this:

public TestA {
	private int n;
	private Timer time;

	public void TestA() {
		n = 0;
		time += nIncrease();
		timer.start();
	}

	private void nIncrease() {
	n = n + 1;
	}

}

- suanmeiguo August 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I am sorry. Is this solution supposed to be for this question?

- Arun Manivannan August 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

It's just what I think

- Suanmeiguo August 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

You posted the answer to another question here, I believe.

- Anonymous August 31, 2012 | Flag
Comment hidden because of low score. Click to expand.
-1
of 3 vote

Override hashCode and return some random number.

- pks August 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Unfortunately, overriding hashcode wont help. The default implementation of Object just checks for reference equality and does not consider hashcode while calling the "equals" method. That said, frankly, I am unable to figure out the answer myself.

- Arun Manivannan August 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

You can make the constructor do:

System.out.println ("false");
System.exit(0);

Hah, take that, Java!

- Anonymous August 31, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

ROFL. Wish there were a "super like" button in career cup

- Arun Manivannan August 31, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thanks for the answer!! :) Thinking why I did not think about such way!

- kinshu August 31, 2012 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Class A{
public boolean equals(Object o)
{
A obj=(A)o;
if(this==obj)
return false;
else
return true;
}
public static void main(String...args)
{
TestA testObj = new TestA();
System.out.println(testObj.equals(testObj));
}
}

- balu August 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Here also the condition is "we cannot overrride equals!!!"

- kinshu August 31, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

class B
{
public boolean equals(Object o) // overriding in the superclass
{B obj=(B)o;
if(this.hashCode()==obj.hashCode())
return false;
else
return true;
}
}
class TestA extends B{
public static void main(String...args)
{
TestA testObj = new TestA();
System.out.println(testObj.equals(testObj));
}
}

- Balu September 01, 2012 | Flag


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