VMware Code Snippets Questions and ANSWERS Quiz-1

Question 1

Time: 00:00:00
What is the output of this C code?

#include
void main()
{
int x = 97;
int y = sizeof(x++);
printf("x is %d", x);
}

x is 97

x is 97

x is 98

x is 98

x is 99

x is 99

Run time error

Run time error

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 2

Time: 00:00:00
What is the output of the below c code?

#include
void main()
{
char *s = "hello";
char *p = s;
printf("%p\t%p", p, s);
}

Different address is printed

Different address is printed

Same address is printed

Same address is printed

Run time error

Run time error

Nothing

Nothing

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 3

Time: 00:00:00
What is the output of this C code?

#include
#define foo(m, n) m * n = 10
int main()
{
printf("in main\n");
}

In main

In main

Compilation error as lvalue is required for the expression m*n=10

Compilation error as lvalue is required for the expression m*n=10

Preprocessor error as lvalue is required for the expression m*n=10

Preprocessor error as lvalue is required for the expression m*n=10

None of the mentioned

None of the mentioned

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 4

Time: 00:00:00
Which of the following code fragments inserted, will allow compiling?

public class Outer
{
public void someOuterMethod()
{
//Line 5
}
public class Inner { }

public static void main(String[] argv)
{
Outer ot = new Outer();
//Line 10
}
}

new Inner(); //At line 5

new Inner(); //At line 5

new Inner(); //At line 10

new Inner(); //At line 10

new ot.Inner(); //At line 10

new ot.Inner(); //At line 10

new Outer.Inner(); //At line 10

new Outer.Inner(); //At line 10

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 5

Time: 00:00:00

What is the widest valid returnType for method in line 3?

public class ReturnIt
{
returnType methodA(byte x, double y) /* Line 3 */
{
return (long)x / y * 2;
}
}

int

int

byte

byte

long

long

double

double

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 6

Time: 00:00:00
What will be the output of the program?

class A
{
final public int GetResult(int a, int b) { return 0; }
}
class B extends A
{
public int GetResult(int a, int b) {return 1; }
}
public class Test
{
public static void main(String args[])
{
B b = new B();
System.out.println("x = " + b.GetResult(0, 1));
}
}

x = 0

x = 0

x = 1

x = 1

Compilation fails.

Compilation fails.

An exception is thrown at runtime.

An exception is thrown at runtime.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 7

Time: 00:00:00
What will be the output of the program?

public class Test
{
public static void main(String args[])
{
class Foo
{
public int i = 3;
}
Object o = (Object)new Foo();
Foo foo = (Foo)o;
System.out.println("i = " + foo.i);
}
}

i = 3

i = 3

Compilation fails.

Compilation fails.

i = 5

i = 5

A ClassCastException will occur.

A ClassCastException will occur.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 8

Time: 00:00:00
What will be the output of the program?


public class A
{
void A() /* Line 3 */
{
System.out.println("Class A");
}
public static void main(String[] args)
{
new A();
}
}

Class A

Class A

Compilation fails.

Compilation fails.

An exception is thrown at line 3.

An exception is thrown at line 3.

The code executes with no output.

The code executes with no output.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

["0","40","60","80","100"]
["Need more practice! \r\n","Keep trying! \r\n","Not bad! \r\n","Good work! \r\n","Perfect! \r\n"]

Personalized Analytics only Availble for Logged in users

Analytics below shows your performance in various Mocks on PrepInsta

Your average Analytics for this Quiz

Rank

-

Percentile

0%

Get over 200+ Courses under One Subscription

mute

Don’t settle Learn from the Best with PrepInsta Prime Subscription

Learn from Top 1%

One Subscription, For Everything

The new cool way of learning and upskilling -

Limitless Learning

One Subscription access everything

Job Assistance

Get Access to PrepInsta Prime

Top Faculty

from FAANG/IITs/TOP MNC's

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others.

Comments