PYQ – UNIT III PROGRAMMING LANGUAGES AND COMPUTER GRAPHICS
Q1) What is the output of the following JAVA Program? [June 2019]
public class Good {
private int m;
public Good (int m){this.m=m;}
public Boolean equals (Good n) {return n.m==m;}
public static void main (string args[]){
Good m1 = new Good(22);
Good m2 = new Good(22);
Object s1 = new Good(22);
Object s2 = new Good(22);
System.out.println(m1.equals(m2));
System.out.println(s1.equals(s2));
System.out.println(m1.equals(s2));
System.out.println(s1.equals(m2));
}
}
a) True, True, False, False
b) True, False, True, False
c) True, True, False, True
d) True, False, False, False
Explanation:
System.out.println(m1.equals(m2)); // Both objects are same. So it is True
System.out.println(s1.equals(s2)); // Both objects are different. So it is false
System.out.println(m1.equals(s2)); // Both objects are different. So it is false
System.out.println(s1.equals(m2)); // Both objects are different. So it is false
Q2) Consider the following C-code fragment running on a 32-bit X86 machine: [June 2019]
typedef struct {
union {
unsigned char a;
unsigned short b;
} U;
unsigned char c;
}S;S B[10];
S*p=&B[4];
S*q=&B[5];
p → U.b=0x1234;
/* structure S takes 32-bits */
If M is the value of q-p and N is the value of ((int) & (p->c)) -((int)p) , then (M,N) is
a) (1,1)
b) (3,2)
c) (1,2)
d) (4,4)
Explanation:
S B[10]; // declaring array of 10 structures
S*p=&B[4]; // Assigning 4th array value to pointer p
S*q=&B[5]; //Assigning 5th array value to pointer q
p → U.b=0x1234; // Assigning a value to 4th structure array element’s union short b
We have to find q-p
q is nothing but address of B[5], say it is 1010
and B[4] is 1008.
Then q-p = (1010-1008)/sizeof(int) = 1
Now, we have to find ((int) & (p->c)) -((int)p)
Here c is char and typecasted to int
And, ((int)p) is ‘short int’ type , it’s size ‘4B’
So, ((int) & (p->c)) -((int)p) = 2
Answer will be C (1,2)
#PYQ - UNIT III PROGRAMMING LANGUAGES AND COMPUTER GRAPHICS #pyq unit 3