Explore topic-wise MCQs in Java Programming.

This section includes 7 Mcqs, each offering curated multiple-choice questions to sharpen your Java Programming knowledge and support exam preparation. Choose a topic below to get started.

1.

What is the output of this program?
import java.util.*;
class genericstack
{
Stack object = new Stack ();
public void push(E obj)
{
object.push(obj);
}
public E pop()
{
E obj = object.pop();
return obj;
}
}

public class Result
{
public static void main(String args[])
{
genericstack genericstackObj0 = new genericstack();
genericstackObj0.push("Inteview");
System.out.print(genericstackObj0.pop() + " ");
genericstack genericstackObj1 = new genericstack();
genericstackObj1.push("Mania");
System.out.println(genericstackObj1.pop());
}
}

A. Mania
B. Interview
C. InterviewMnai
D. Inerview Mania
E. None of these
Answer» E. None of these
2.

What is the output of this program?
import java.util.*;
class genericstack
{
Stack object = new Stack ();
public void push(E obj)
{
object.push(obj);
}
public E pop()
{
E obj = object.pop();
return obj;
}
}

public class Output
{
public static void main(String args[])
{
genericstack genericObject = new genericstack();
genericObject.push(50);
System.out.println(genericObject.pop());
}
}

A. 0
B. 30
C. 50
D. Compilation Error
E. Runtime Error
Answer» D. Compilation Error
3.

What is the output of this program?
import java.util.*;
class genericstack
{
Stack object = new Stack ();
public void push(E obj)
{
object.push(obj);
}
public E pop()
{
E obj = object.pop();
return obj;
}
}

public class Output
{
public static void main(String args[])
{
genericstack genericObject = new genericstack();
genericObject.push(100);
System.out.println(genericObject.pop());
}
}

A. 10
B. 20
C. 30
D. 40
E. 100
Answer» F.
4.

What is the output of this program?
import java.util.*;
class genericstack
{
Stack object = new Stack ();
public void push(E obj)
{
object.push(obj);
}
public E pop()
{
E obj = object.pop();
return obj;
}
}

public class Output
{
public static void main(String args[])
{
genericstack genericstackObj = new genericstack();
genericstackObj.push("Interview Mania");
System.out.println(genericstackObj.pop());
}
}

A. Interview Mania
B. Mania
C. Interviiw
D. Compilation Error
E. Runtime Error
Answer» E. Runtime Error
5.

What is the output of this program?
import java.util.*;
public class Result
{
public static double sumOfList(List extends Number> list)
{
double var = 0.0;
for (Number num : list)
var += num.doubleValue();
return var;
}
public static void main(String args[])
{
List obj = Arrays.asList(4.3, 5.6, 7.8);
System.out.println(sumOfList(obj));
}
}

A. 17.7
B. 4.3
C. 5.6
D. 7.8
E. None of these
Answer» B. 4.3
6.

What is the output of this program?
import java.util.*;
public class Result
{
public static double sumOfList(List extends Number> list)
{
double var = 0.0;
for (Number num : list)
var += num.doubleValue();
return var;
}
public static void main(String args[])
{
List ListObject = Arrays.asList(10, 20, 30);
System.out.println(sumOfList(ListObject));
}
}

A. 10
B. 20.0
C. 30.0
D. 50.0
E. 60.0
Answer» F.
7.

What is the output of this program?
import java.util.*;
class genericstack
{
Stack object = new Stack ();
public void push(E obj)
{
object.push(obj);
}

public E pop()
{
E obj = object.pop();
return obj;
}
}

public class Output
{
public static void main(String args[])
{
genericstack genericObj = new genericstack();
genericObj.push("Interview");
System.out.println(genericObj.pop());
}
}

A. Interview
B. InterviewMania
C. Interviw Mania
D. Compilation Error
E. Runtime Error
Answer» B. InterviewMania