You can boost your Grade 10 2026 exam preparation with this EmSAT Java Mock Test (available with detailed solutions).. This mock test has been designed with the analysis of important topics, recent trends of the exam, and previous year questions of the last 3-years. All the questions have been designed to mirror the official pattern of Grade 10 2026 exam, helping you build speed, accuracy as per the actual exam.
Mock Test Highlights:
Sign up on EduRev for free and get access to these mock tests, get your All India Rank, and identify your weak areas to improve your marks & rank in the actual exam.
Predict the output of following program. Note that fun() is public in base and private in derived.
class Base {
public void foo() { System.out.println("Base"); }
}
class Derived extends Base {
private void foo() { System.out.println("Derived"); }
}
public class Main {
public static void main(String args[]) {
Base b = new Derived();
b.foo();
}
}
Detailed Solution: Question 1
Predict the output of following Java Program
// filename Main.java
class Grandparent {
public void Print() {
System.out.println("Grandparent's Print()");
}
}
class Parent extends Grandparent {
public void Print() {
System.out.println("Parent's Print()");
}
}
class Child extends Parent {
public void Print() {
super.super.Print();
System.out.println("Child's Print()");
}
}
public class Main {
public static void main(String[] args) {
Child c = new Child();
c.Print();
}
}
Detailed Solution: Question 2
Detailed Solution: Question 3
Predict the output?
// file name: Main.java
public class Main {
public static void main(String args[]) {
int arr[] = {10, 20, 30, 40, 50};
for(int i=0; i < arr.length; i++)
{
System.out.print(" " + arr[i]);
}
}
}
Detailed Solution: Question 4
Which of the following is a valid Java data type for storing a true/false value?
Detailed Solution: Question 5
Predict the output of the following program.
class Test
{
public static void main(String[] args)
{
Double object = new Double("2.4");
int a = object.intValue();
byte b = object.byteValue();
float d = object.floatValue();
double c = object.doubleValue();
System.out.println(a + b + c + d );
}
}
Detailed Solution: Question 6
Predict the output of following Java program.
class Test {
public static void main(String[] args) {
for(int i = 0; 0; i++)
{
System.out.println("Hello");
break;
}
}
}
Detailed Solution: Question 7
class Main {
public static void main(String args[]) {
int t;
System.out.println(t);
}
}
Detailed Solution: Question 8
Predict the output of following Java program
class T {
int t = 20;
T() {
t = 40;
}
}
class Main {
public static void main(String args[]) {
T t1 = new T();
System.out.println(t1.t);
}
}
Detailed Solution: Question 9
Predict the output?
package main;
class T {
int t = 20;
}
class Main {
public static void main(String args[]) {
T t1 = new T();
System.out.println(t1.t);
}
}
Detailed Solution: Question 10
Output of following Java program
class Point {
int m_x, m_y;
public Point(int x, int y) { m_x = x; m_y = y; }
public Point() { this(10, 10); }
public int getX() { return m_x; }
public int getY() { return m_y; }
public static void main(String args[]) {
Point p = new Point();
System.out.println(p.getX());
}
}
Detailed Solution: Question 11
What is the output of the following Java program?
final class Complex {
private double re, im;
public Complex(double re, double im) {
this.re = re;
this.im = im;
}
Complex(Complex c) {
System.out.println("Copy constructor called");
re = c.re;
im = c.im;
}
public String toString() {
return "(" + re + " + " + im + "i)";
}
}
class Main {
public static void main(String[] args) {
Complex c1 = new Complex(10, 15);
Complex c2 = new Complex(c1);
Complex c3 = c1;
System.out.println(c2);
}
}
Detailed Solution: Question 12
What is the output of the following Java program?
class Test
{
static int a;
static
{
a = 4;
System.out.println("inside static block");
System.out.println("a = " + a);
}
Test()
{
System.out.println("inside constructor");
a = 10;
}
public static void func()
{
a = a + 1;
System.out.println("a = " + a);
}
public static void main(String[] args)
{
Test obj = new Test();
obj.func();
}
}
Detailed Solution: Question 13
What is the output of the below Java Code?
class Test extends Exception { }
class Main {
public static void main(String args[]) {
try {
throw new Test();
}
catch(Test t) {
System.out.println("Got the Test Exception");
}
finally {
System.out.println("Inside finally block ");
}
}
}
Detailed Solution: Question 14
Predict the output of following Java program
class Main {
public static void main(String args[]) {
try {
throw 10;
}
catch(int e) {
System.out.println("Got the Exception " + e);
}
}
}
Detailed Solution: Question 15
What is the output of the below Java Code?
class Base extends Exception {}
class Derived extends Base {}
public class Main {
public static void main(String args[]) {
// some other stuff
try {
// Some monitored code
throw new Derived();
}
catch(Base b) {
System.out.println("Caught base class exception");
}
catch(Derived d) {
System.out.println("Caught derived class exception");
}
}
}
Detailed Solution: Question 16
Predict the output of the following program.
class Test
{ int count = 0;
void A() throws Exception
{
try
{
count++;
try
{
count++;
try
{
count++;
throw new Exception();
}
catch(Exception ex)
{
count++;
throw new Exception();
}
}
catch(Exception ex)
{
count++;
}
}
catch(Exception ex)
{
count++;
}
}
void display()
{
System.out.println(count);
}
public static void main(String[] args) throws Exception
{
Test obj = new Test();
obj.A();
obj.display();
}
}
Detailed Solution: Question 17
Which of these is a super class of all errors and exceptions in the Java language?
Detailed Solution: Question 18
The built-in base class in Java, which is used to handle all exceptions is
Detailed Solution: Question 19
Predict the output of the following program.
class Test
{
String str = "a";
void A()
{
try
{
str +="b";
B();
}
catch (Exception e)
{
str += "c";
}
}
void B() throws Exception
{
try
{
str += "d";
C();
}
catch(Exception e)
{
throw new Exception();
}
finally
{
str += "e";
}
str += "f";
}
void C() throws Exception
{
throw new Exception();
}
void display()
{
System.out.println(str);
}
public static void main(String[] args)
{
Test object = new Test();
object.A();
object.display();
}
}
Detailed Solution: Question 20
What is the output of the below Java Code?
class Test
{
public static void main (String[] args)
{
try
{
int a = 0;
System.out.println ("a = " + a);
int b = 20 / a;
System.out.println ("b = " + b);
}
catch(ArithmeticException e)
{
System.out.println ("Divide by zero error");
}
finally
{
System.out.println ("inside the finally block");
}
}
}
Detailed Solution: Question 21
What is the output of the below Java Code?
class Test
{
public static void main(String[] args)
{
try
{
int a[]= {1, 2, 3, 4};
for (int i = 1; i <= 4; i++)
{
System.out.println ("a[" + i + "]=" + a[i] + "\\n");
}
}
catch (Exception e)
{
System.out.println ("error = " + e);
}
catch (ArrayIndexOutOfBoundsException e)
{
System.out.println ("ArrayIndexOutOfBoundsException");
}
}
}
Detailed Solution: Question 22
public class Myfile
{
public static void main (String[] args)
{
String biz = args[1];
String baz = args[2];
String rip = args[3];
System.out.println("Arg is " + rip);
}
}
Select how you would start the program to cause it to print: Arg is 2
Detailed Solution: Question 23
Which of the following are valid calls to Math.max?
1. Math.max(1,4)
2. Math.max(2.3, 5)
3. Math.max(1, 3, 5, 7)
4. Math.max(-1.5, -2.8f)
Detailed Solution: Question 24
Detailed Solution: Question 25
What is the value of "d" after this line of code has been executed?
double d = Math.round ( 2.5 + Math.random() );
Detailed Solution: Question 26
public class Test2
{
public static int x;
public static int foo(int y)
{
return y * 2;
}
public static void main(String [] args)
{
int z = 5;
assert z > 0; /* Line 11 */
assert z > 2: foo(z); /* Line 12 */
if ( z < 7 )
assert z > 4; /* Line 14 */
switch (z)
{
case 4: System.out.println("4 ");
case 5: System.out.println("5 ");
default: assert z < 10;
}
if ( z < 10 )
assert z > 4: z++; /* Line 22 */
System.out.println(z);
}
}
which line is an example of an inappropriate use of assertions?
Detailed Solution: Question 27
What will be the output of the program (when you run with the -ea option) ?
public class Test
{
public static void main(String[] args)
{
int x = 0;
assert (x > 0) : "assertion failed"; /* Line 6 */
System.out.println("finished");
}
}
Detailed Solution: Question 28
What will be the output of the program?
public class Test
{
public static int y;
public static void foo(int x)
{
System.out.print("foo ");
y = x;
}
public static int bar(int z)
{
System.out.print("bar ");
return y = z;
}
public static void main(String [] args )
{
int t = 0;
assert t > 0 : bar(7);
assert t > 1 : foo(8); /* Line 18 */
System.out.println("done ");
}
}
Detailed Solution: Question 29
public class Test
{
public void foo()
{
assert false; /* Line 5 */
assert false; /* Line 6 */
}
public void bar()
{
while(true)
{
assert false; /* Line 12 */
}
assert false; /* Line 14 */
}
}
What causes compilation to fail?
Detailed Solution: Question 30
28 videos|254 docs|56 tests |