Programming Questions

Q:

public abstract interface Frobnicate { public void twiddle(String s); } 

Which is a correct class?

A) public abstract class Frob implements Frobnicate { public abstract void twiddle(String s) { } } B) public abstract class Frob implements Frobnicate { }
C) public class Frob extends Frobnicate { public void twiddle(Integer i) { } } D) public class Frob implements Frobnicate { public void twiddle(Integer i) { } }
 
Answer & Explanation Answer: B) public abstract class Frob implements Frobnicate { }

Explanation:

B is correct, an abstract class need not implement any or all of an interface’s methods

Report Error

View Answer Report Error Discuss

Filed Under: Programming

2 15672
Q:

How many times i value is checked in the below code?

       #include <stdio.h>
        int main()
        {
            int i = 0;
            do {
                i++;
                printf( "In while loopn" );
            } while (i < 3);
        }

A) 2 B) 3
C) 4 D) 1
 
Answer & Explanation Answer: B) 3

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

5 15205
Q:

What will be output when you will execute following c code?

#include <stdio.h>
void main()

{
    int const SIZE = 5;
    int expr;
    double value[SIZE] = { 2.0, 4.0, 6.0, 8.0, 10.0 };
    expr=1|2|3|4;
    printf ( "%f", value[expr] );
}

A) 2.000000 B) 4.000000
C) 8.000000 D) Compilation error
 
Answer & Explanation Answer: D) Compilation error

Explanation:

Size of any array in c cannot be constantan variable.

Report Error

View Answer Report Error Discuss

Filed Under: Programming

5 15030
Q:

Which of the following statement is true?

A) Cohesion is the OO principle most closely associated with hiding implementation details B) Cohesion is the OO principle most closely associated with making sure that classes know about other classes only through their APIs
C) Cohesion is the OO principle most closely associated with making sure that a class is designed with a single, well-focused purpose D) None
 
Answer & Explanation Answer: C) Cohesion is the OO principle most closely associated with making sure that a class is designed with a single, well-focused purpose

Explanation:

A refers to encapsulation, B refers to coupling

Report Error

View Answer Report Error Discuss

Filed Under: Programming

4 14396
Q:

What is the output of this C code?

       #include <stdio.h>
        void main()
        {
            int x = 1, z = 3;
            int y = x << 3;
            printf( "%dn", y );
        }

A) -2147483648 B) -1
C) Run time error D) 8
 
Answer & Explanation Answer: D) 8

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

2 14289
Q:

What will be output of the following c program ?

#include

int main()

{

    int max-val=100;

    int min-val=10;

    int avg-val;

    avg-val =( max-val + min-val ) / 2;

    printf( "%d", avg-val );

    return 0;

}

A) 55 B) 105
C) 60 D) Compilation error
 
Answer & Explanation Answer: D) Compilation error

Explanation:

We cannot use special character – in the variable name.
Variable name can have only underscore.

Report Error

View Answer Report Error Discuss

Filed Under: Programming

5 13540
Q:

Output of the Program :

main()

{

int i = 1;

while (i <= 5)

    {

         printf( "%d", i );

         if (i > 2) goto here;

         i++;

     }

}

fun()

{

here : printf( "PP" );

}

A) 1 B) 2
C) Compilation error D) Exception occurs
 
Answer & Explanation Answer: C) Compilation error

Explanation:

Compiler error: Undefined label 'here' in function main

Report Error

View Answer Report Error Discuss

Filed Under: Programming

3 12957
Q:

What will be output of following program ?

#include
int main()

{

int a = 10;
void *p = &a;
int *ptr = p;
printf("%u",*ptr);
return 0;

}

A) 10 B) Address
C) 2 D) Compilation error
 
Answer & Explanation Answer: A) 10

Explanation:

Void pointer can hold address of any data type without type casting. Any pointer can hold void pointer without type casting.

Report Error

View Answer Report Error Discuss

Filed Under: Programming

1 12618