Monday 16 November 2015

Member of Technical Staff - PTC Software Online Test

Q1. What is printed on javascript console when executing below program?

function() {
    (function() {
        var a = b = 3;
    })();
    console.log("a undefined? " + (typeof a === 'undefined'));
    console.log("b undefined? " + (typeof b === 'undefined'));
}();

1. true true
2. false true
3. true false
4. false false

Q2. What is the output of the following program?
class Question
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        HashSet set = new HashSet();
        Name name = new Name("Content");
        set.add(name);
        name.setName("Content Media");

        System.out.println(set.contains(name));
    }
}

class Name {
    private String name;

    pubic Name (String name) {
        this.name = name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((name == null) > 0 : name.hashCode());
        return result;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass != obj.getClass()) {
            return false;
        }
        Name other = (Name) obj;
        if (name == null) {
            if (other.name != null) {
                return false;
            }
        }
        else if (!name.equals(other.name)) {
            return false;
        }
        return true;
    }
}

1. false        2. true




Q3. What is the output of the following program?
class Question
{
    public static void main (String[] args) throws java.lang.Exception
    {
        start();
    }
    
    static void start() {
        long[] a1 = {3,4,5};
        long[] a2 = fix(a1);
        System.out.print(a1[0] + a1[1] + a1[2] + " ");
        System.out.print(a2[0] + a2[1] + a2[2]);
    }
    
    static long[] fix(long[] a) {
        a[1] = 7;
        return a;
    }
}

a. 3  7  5  3  7  5
b. 3  4  5  3  7  5
c. 12  15
d. 15  15


Q4. What is the output of the following program?
class Question
{
    public static void main (String[] args) throws java.lang.Exception
    {
        int[] a = {1};
        increment(a);
        System.out.println(a[a.length -1]);
    }
    
    static void increment(int[] i) {
        i[i.length - 1]++;
    }
}

1. Compiler Error
2. Compiles and runs printing out 2
3. Compiles and runs printing out 1
4. An ArrayIndexOutOfBounds Exception at runtime


Q5. Conside the following JavaScript function
function foo() {
     return 5;
}
What will the following code do?
var myVar = foo;

Select the correct answer
1. Assigns the integer 5 to the variable myVar
2. Assigns the pointer to the function foo to myVar
3. Throws an exception
4. Do Nothing


Q6. In how many different ways can the letters of the word 'OPTICAL' can be arranged so that the vowels always come together?
a. 120    b. 720    c. 4320    d. 2160    e. None of these


Q7. Find the ratio in which rice at Rs 7.2 a kg be mixed with rice at Rs 5.7 a kg to produce a mixture worth Rs 6.3 a kg.
a. 1:3    b. 2:3    c. 3:4    d. 4:5


Q8 Select all the correct output that apply
String string1 = "Harsh";
String string2 = new String("Harsh");
String string3 = string2.intern();

a. (string1 == string2) is true
b. (string1 == string2) is false
c. (string2 == string3) is true
d. (string2 == string3) is false
e. (string1 == string3) is true
f. (string1 == string3) is false
g. string1.equals(string3) is true


Q9. Write a program to return true if the string has a pattern such that for str = abababab then string can be written as str = n*(tempstr) such that tempstr = ab
Thus your program should return true if the string has occurrences of such pattern only else false.
Example Test Case
abab
abcabcabc
abcdabcd

Negative Case
axxbyyczz
abcabcxyz


Q10. Write a program to generate all permutations of 7 digit telephone numbers such that for every digit we have a set of 3 alphabets configured as below except 0 and 1

 1       2       3
         abc   def
 4       5       6
ghi     jkl     mno
 7       8       9
prs    tuv     wxy
          0

No comments :

Post a Comment