All Exams  >   EmSAT Achieve  >   Mock Tests for EmSAT Achieve 2025  >   All Questions

All questions of Java for EmSAT Achieve Exam

Which is valid declaration of a float?
  • a)
    float f = 1F;
  • b)
    float f = 1.0;
  • c)
    float f = "1";
  • d)
    float f = 1.0d;
Correct answer is option 'A'. Can you explain this answer?

Understanding Float Declarations
In programming, particularly in languages like Java and C#, the declaration of a float variable must adhere to specific syntax and rules regarding data types. Let's analyze the options provided in the question.
Option A: float f = 1F;
- This is a valid declaration.
- The 'F' postfix indicates that the literal '1' is a float.
- It explicitly specifies the number as a float type, which is crucial for correct variable assignment.
Option B: float f = 1.0;
- This is not a valid declaration for a float.
- The literal '1.0' is treated as a double by default in many programming languages.
- This can lead to a mismatch error, as a float cannot be directly assigned a double value without casting.
Option C: float f = "1";
- This is also not valid.
- Assigning a string (in this case, "1") to a float variable is incompatible.
- The types must match; a string cannot be converted to a float directly without parsing.
Option D: float f = 1.0d;
- This is not valid for a float declaration.
- The 'd' suffix indicates a double literal.
- Similar to option B, you cannot assign a double to a float without explicit casting.
Conclusion
- The only valid declaration among the options is option A: `float f = 1F;`.
- This highlights the importance of understanding data types and their specific representations in programming.
- Always use the correct suffixes to avoid type mismatches and ensure smooth code execution.

You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provides that capability?
  • a)
    java.util.Map
  • b)
    java.util.Set
  • c)
    java.util.List
  • d)
    java.util.Collection
Correct answer is option 'B'. Can you explain this answer?

Eissa Al Hajri answered
Understanding the Requirement
To store elements without duplicates and in natural order, the right data structure is crucial. Let's analyze the options available.
Option A: java.util.Map
- A Map stores key-value pairs, where each key is unique.
- However, it doesn't enforce any order on the keys and is not suitable for simple collections of elements.
Option B: java.util.Set
- A Set is specifically designed to hold unique elements.
- It automatically prevents duplicates and offers a natural ordering if implemented via a specific class like TreeSet.
- This makes it the ideal choice for this requirement.
Option C: java.util.List
- A List allows for duplicate elements and maintains the order of insertion.
- While it does provide access in a natural order, it does not meet the uniqueness requirement.
Option D: java.util.Collection
- Collection is a broader interface that encompasses other collections like List, Set, and Queue.
- It does not specify behavior regarding duplicates or ordering.
Conclusion
The best option for storing elements without duplicates while ensuring they can be accessed in natural order is option B: java.util.Set. This structure guarantees uniqueness and, when using implementations like TreeSet, maintains the elements in their natural order.

public class Test { }
What is the prototype of the default constructor?
  • a)
    Test( )
  • b)
    Test(void)
  • c)
    public Test( )
  • d)
    public Test(void)
Correct answer is option 'C'. Can you explain this answer?

Option A and B are wrong because they use the default access modifier and the access modifier for the class is public (remember, the default constructor has the same access modifier as the class).
Option D is wrong. The void makes the compiler think that this is a method specification - in fact if it were a method specification the compiler would spit it out.

Which will contain the body of the thread?
  • a)
    run();
  • b)
    start();
  • c)
    stop();
  • d)
    main();
Correct answer is option 'A'. Can you explain this answer?

Sara Al Khouri answered
Understanding Thread Methods in Java
In Java, threads are essential for concurrent programming, and understanding the methods related to thread management is crucial. The question asks which method contains the body of the thread. The correct answer is option 'A'—run().
What is the run() Method?
- The run() method is where the code that constitutes the thread’s task is defined.
- When a thread is started, the run() method is invoked, and this is where the thread's execution begins.
How the run() Method Works
- You define the run() method in a class that implements the Runnable interface or extends the Thread class.
- This method encapsulates the logic that you want to execute in a separate thread.
Other Methods Explained
- start() Method:
- This method is used to initiate a thread.
- It calls the run() method internally but does not contain the thread's body itself.
- stop() Method:
- This method is deprecated and was used to terminate a thread abruptly.
- It does not relate to the thread's body and is not safe for thread management.
- main() Method:
- This is the entry point of any Java application.
- It is not related to thread execution but serves as the starting point for the Java program.
Conclusion
In summary, the run() method is the heart of thread execution, containing the code that operates within the thread. Understanding this distinction between these methods is essential for effective thread management in Java programming.

What is the name of the method used to start a thread execution?
  • a)
    init();
  • b)
    start();
  • c)
    run();
  • d)
    resume();
Correct answer is option 'B'. Can you explain this answer?

Understanding Thread Execution in Java
In Java, threads are essential for concurrent programming, allowing multiple tasks to run simultaneously. When dealing with threads, it is crucial to understand how to initiate their execution.
Correct Method: start()
The method used to start thread execution is:
- start(): This method is responsible for launching a new thread. When you call `start()`, it invokes the `run()` method in a new thread of execution.
Why not the other options?
- init():
- This method is not related to thread execution. It is generally used for initializing components, particularly in applets or servlets.
- run():
- This method contains the code that defines what the thread will do when it runs. However, calling `run()` directly does not start a new thread; it executes the method in the current thread.
- resume():
- This method is deprecated and was used to resume a thread that was previously suspended. It does not initiate new thread execution.
Key Takeaways
- start() is essential for thread execution, as it sets up a new thread and calls the `run()` method automatically.
- Understanding the distinction between `start()` and `run()` is crucial for effective multithreading in Java.
Using the correct method to manage threads ensures efficient and effective concurrent programming in your applications.

Which cannot directly cause a thread to stop executing?
  • a)
    Calling the SetPriority() method on a Thread object.
  • b)
    Calling the wait() method on an object.
  • c)
    Calling notify() method on an object.
  • d)
    Calling read() method on an InputStream object.
Correct answer is option 'C'. Can you explain this answer?

Understanding Thread Behavior in Java
In Java, thread management is crucial for efficient multitasking. The question pertains to what actions can directly stop a thread from executing. Let's analyze the options provided:
Option A: SetPriority() Method
- This method allows you to set the priority of a thread, influencing its scheduling. However, it does not directly stop a thread from executing; it merely affects the order in which threads are run.
Option B: wait() Method
- The `wait()` method causes the current thread to wait until another thread invokes `notify()` or `notifyAll()` on the same object. While this does pause the thread, it doesn't stop it permanently; the thread can resume when notified.
Option C: notify() Method
- The `notify()` method wakes up a single thread that is waiting on an object's monitor. It does not directly stop a thread; rather, it allows a waiting thread to continue executing. Therefore, this option is indeed the correct answer as it does not directly cause any thread to stop.
Option D: read() Method on InputStream
- The `read()` method can block a thread until data is available, but it doesn’t inherently stop the thread. It simply pauses it until it can proceed.
Conclusion
In summary, the `notify()` method does not inherently cause a thread to stop executing, making it the right answer. Understanding these nuances is key to mastering thread management in Java.

class X2 
{
    public X2 x;
    public static void main(String [] args) 
    {
        X2 x2 = new X2();  /* Line 6 */
        X2 x3 = new X2();  /* Line 7 */
        x2.x = x3;
        x3.x = x2;
        x2 = new X2();
        x3 = x2; /* Line 11 */
        doComplexStuff();
    }
}
after line 11 runs, how many objects are eligible for garbage collection?
  • a)
    0
  • b)
    1
  • c)
    2
  • d)
    3
Correct answer is option 'C'. Can you explain this answer?

Understanding Object Eligibility for Garbage Collection
To determine how many objects are eligible for garbage collection after line 11, we need to analyze the object references in the code.
Object Creation
- At line 6, `X2 x2 = new X2();` creates Object A.
- At line 7, `X2 x3 = new X2();` creates Object B.
Reference Assignment
- `x2.x = x3;` makes Object A reference Object B.
- `x3.x = x2;` makes Object B reference Object A.
At this point:
- Object A references Object B.
- Object B references Object A.
Reassigning References
- `x2 = new X2();` creates Object C and makes `x2` now reference Object C. Object A still references Object B and vice versa.
- `x3 = x2;` makes `x3` reference Object C.
After line 11:
- Object A (previously `x2`) and Object B (previously `x3`) are still referencing each other.
- Object C (newly created) is referenced by both `x2` and `x3`.
Garbage Collection Eligibility
- Object A and Object B are still reachable due to their mutual references.
- Object C is actively referenced by both `x2` and `x3`.
Conclusion
- After line 11, Object A and Object B are not eligible for garbage collection as they are still referenced.
- Therefore, no objects are eligible for garbage collection.
The correct answer is option C: 2 objects (A and B) are still referenced and not eligible for garbage collection.

public class MyRunnable implements Runnable 
{
    public void run() 
    {
        // some code here
    }
}
which of these will create and start this thread?
  • a)
    new Runnable(MyRunnable).start();
  • b)
    new Thread(MyRunnable).run();
  • c)
    new Thread(new MyRunnable()).start();
  • d)
    new MyRunnable().start();
Correct answer is option 'C'. Can you explain this answer?

Because the class implements Runnable, an instance of it has to be passed to the Thread constructor, and then the instance of the Thread has to be started.
A is incorrect. There is no constructor like this for Runnable because Runnable is an interface, and it is illegal to pass a class or interface name to any constructor.
B is incorrect for the same reason; you can't pass a class or interface name to any constructor.
D is incorrect because MyRunnable doesn't have a start() method, and the only start() method that can start a thread of execution is the start() in the Thread class.

Which is a valid keyword in java?
  • a)
    interface
  • b)
    string
  • c)
    Float
  • d)
    unsigned
Correct answer is option 'A'. Can you explain this answer?

interface is a valid keyword.
Option B is wrong because although "String" is a class type in Java, "string" is not a keyword.
Option C is wrong because "Float" is a class type. The keyword for the Java primitive is float.Option D is wrong because
"unsigned" is a keyword in C/C++ but not in Java.

Which collection class allows you to associate its elements with key values, and allows you to retrieve objects in FIFO (first-in, first-out) sequence?
  • a)
    java.util.ArrayList
  • b)
    java.util.LinkedHashMap
  • c)
    java.util.HashMap
  • d)
    java.util.TreeMap
Correct answer is option 'B'. Can you explain this answer?

LinkedHashMap is the collection class used for caching purposes. FIFO is another way to indicate caching behavior. To retrieve LinkedHashMap elements in cached order, use the values() method and iterate over the resultant collection.

Which cause a compiler error?
  • a)
    int[ ] scores = {3, 5, 7};
  • b)
    int [ ][ ] scores = {2,7,6}, {9,3,45};
  • c)
    String cats[ ] = {"Fluffy", "Spot", "Zeus"};
  • d)
    boolean results[ ] = new boolean [] {true, false, true};
Correct answer is option 'B'. Can you explain this answer?

Option B generates a compiler error: <identifier> expected. The compiler thinks you are trying to create two arrays because there are two array initialisers to the right of the equals, whereas your intention was to create one 3 x 3 two-dimensional array.
To correct the problem and make option B compile you need to add an extra pair of curly brackets:
int [ ] [ ] scores = { {2,7,6}, {9,3,45} };

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)
  • a)
    1, 2 and 4
  • b)
    2, 3 and 4
  • c)
    1, 2 and 3
  • d)
    3 and 4
Correct answer is option 'A'. Can you explain this answer?

(1), (2), and (4) are correct. The max() method is overloaded to take two arguments of type int, long, float, or double.
(3) is incorrect because the max() method only takes two arguments.

Which three are methods of the Object class?
1. notify();
2. notifyAll();
3. isInterrupted();
4. synchronized();
5. interrupt();
6. wait(long msecs);
7. sleep(long msecs);
8. yield();
  • a)
    1, 2, 4
  • b)
    2, 4, 5
  • c)
    1, 2, 6
  • d)
    2, 3, 4
Correct answer is option 'C'. Can you explain this answer?

(1), (2), and (6) are correct. They are all related to the list of threads waiting on the specified object.
(3), (5), (7), and (8) are incorrect answers. The methods isInterrupted() and interrupt() are instance methods of Thread.
The methods sleep() and yield() are static methods of Thread.
D is incorrect because synchronized is a keyword and the synchronized() construct is part of the Java language.

You want a class to have access to members of another class in the same package. Which is the most restrictive access that accomplishes this objective?
  • a)
    public
  • b)
    private
  • c)
    protected
  • d)
    default access
Correct answer is option 'D'. Can you explain this answer?

The only two real contenders are C and D. Protected access Option C makes a member accessible only to classes in the same package or subclass of the class. While default access Option D makes a member accessible only to classes in the same package.

Which will legally declare, construct, and initialize an array?
  • a)
    int [] myList = {"1", "2", "3"};
  • b)
    int [] myList = (5, 8, 2);
  • c)
    int myList [] [] = {4,9,7,0};
  • d)
    int myList [] = {4, 3, 7};
Correct answer is option 'D'. Can you explain this answer?

The only legal array declaration and assignment statement is Option D
Option A is wrong because it initializes an int array with String literals.
Option B is wrong because it use something other than curly braces for the initialization.
Option C is wrong because it provides initial values for only one dimension, although the declared array is a two-dimensional array.

The built-in base class in Java, which is used to handle all exceptions is
  • a)
    Raise
  • b)
    Exception
  • c)
    Error
  • d)
    Throwable
Correct answer is option 'D'. Can you explain this answer?

The Throwable class is the built-in base class for both errors and exceptions in Java. It is the parent class for Exception and Error. While Exception handles exceptions that can be caught and handled by the program, Error represents serious issues (like JVM errors) that are generally not handled by the program. So the correct answer is "Throwable".

What is the value of "d" after this line of code has been executed?
double d = Math.round ( 2.5 + Math.random() );
  • a)
    2
  • b)
    3
  • c)
    4
  • d)
    2.5
Correct answer is option 'B'. Can you explain this answer?

The Math.random() method returns a number greater than or equal to 0 and less than 1 . Since we can then be sure that the sum of that number and 2.5 will be greater than or equal to 2.5 and less than 3.5, we can be sure that Math.round() will round that number to 3. So Option B is the answer.

Assume the following method is properly synchronized and called from a thread A on an object B:
wait(2000);
After calling this method, when will the thread A become a candidate to get another turn at the CPU?
  • a)
    After thread A is notified, or after two seconds.
  • b)
    After the lock on B is released, or after two seconds.
  • c)
    Two seconds after thread A is notified.
  • d)
    Two seconds after lock B is released.
Correct answer is option 'A'. Can you explain this answer?

Option A. Either of the two events (notification or wait time expiration) will make the thread become a candidate for running again.
Option B is incorrect because a waiting thread will not return to runnable when the lock is released, unless a notification occurs.
Option C is incorrect because the thread will become a candidate immediately after notification, not two seconds afterwards.
Option D is also incorrect because a thread will not come out of a waiting pool just because a lock has been released.

What is the numerical range of char?
  • a)
    0 to 32767
  • b)
    0 to 65535
  • c)
    -256 to 255
  • d)
    -32768 to 32767
Correct answer is option 'B'. Can you explain this answer?

The char type is integral but unsigned. The range of a variable of type char is from 0 to 216-1 or 0 to 65535. Java characters are Unicode, which is a 16-bit encoding capable of representing a wide range of international characters. If the most significant nine bits of a char are 0, then the encoding is the same as seven-bit ASCII.

Which of the following are Java reserved words?
1. run
2. import
3. default
4. implement
  • a)
    1 and 2
  • b)
    2 and 3
  • c)
    3 and 4
  • d)
    2 and 4
Correct answer is option 'B'. Can you explain this answer?

(2) - This is a Java keyword
(3) - This is a Java keyword
(1) - Is incorrect because although it is a method of Thread/Runnable it is not a keyword
(4) - This is not a Java keyword the keyword is implements

Which is true about a method-local inner class?
  • a)
    It must be marked final.
  • b)
    It can be marked abstract.
  • c)
    It can be marked public.
  • d)
    It can be marked static.
Correct answer is option 'B'. Can you explain this answer?

Option B is correct because a method-local inner class can be abstract, although it means a subclass of the inner class must be created if the abstract class is to be used (so an abstract method-local inner class is probably not useful).
Option A is incorrect because a method-local inner class does not have to be declared final (although it is legal to do so).
C and D are incorrect because a method-local inner class cannot be made public (remember-you cannot mark any local variables as public), or static.

Which of the following is a valid Java data type for storing a true/false value?
  • a)
    int
  • b)
    float
  • c)
    boolean
  • d)
    String
Correct answer is option 'C'. Can you explain this answer?

The boolean data type in Java is used to store a true or false value. int is used for integers, float is for decimal values, and String is for storing sequences of characters.

Which method must be defined by a class implementing the java.lang.Runnable interface?
  • a)
    void run()
  • b)
    public void run()
  • c)
    public void start()
  • d)
    void run(int priority)
Correct answer is option 'B'. Can you explain this answer?

Option B is correct because in an interface all methods are abstract by default therefore they must be overridden by the implementing class. The Runnable interface only contains 1 method, the void run() method therefore it must be implemented.
Option A and D are incorrect because they are narrowing the access privileges i.e. package(default) access is narrower than public access.
Option C is not method in the Runnable interface therefore it is incorrect.

Which class or interface defines the wait(), notify(),and notifyAll() methods?
  • a)
    Object
  • b)
    Thread
  • c)
    Runnable
  • d)
    Class
Correct answer is option 'A'. Can you explain this answer?

The Object class defines these thread-specific methods.
Option B, C, and D are incorrect because they do not define these methods. And yes, the Java API does define a class called Class, though you do not need to know it for the exam.

What will be the output of the program?
public class Foo 
{  
    public static void main(String[] args) 
    {
        try 
        { 
            return; 
        } 
        finally 
        {
            System.out.println( "Finally" ); 
        } 
    } 
}
  • a)
    Finally
  • b)
    Compilation fails.
  • c)
    The code runs with no output.
  • d)
    An exception is thrown at runtime.
Correct answer is option 'A'. Can you explain this answer?

If you put a finally block after a try and its associated catch blocks, then once execution enters the try block, the code in that finally block will definitely be executed except in the following circumstances:
An exception arising in the finally block itself.
The death of the thread.
The use of System.exit()
Turning off the power to the CPU.
I suppose the last three could be classified as VM shutdown.

interface Base 
{
    boolean m1 ();
    byte m2(short s);
}
which two code fragments will compile?
1. interface Base2 implements Base {}
2. abstract class Class2 extends Base
{ public boolean m1(){ return true; }}
3. abstract class Class2 implements Base {}
4. abstract class Class2 implements Base
{ public boolean m1(){ return (7 > 4); }}
5. abstract class Class2 implements Base
{ protected boolean m1(){ return (5 > 7) }}
  • a)
    1 and 2
  • b)
    2 and 3
  • c)
    3 and 4
  • d)
    1 and 5
Correct answer is option 'C'. Can you explain this answer?

(3) is correct because an abstract class doesn't have to implement any or all of its interface's methods. (4) is correct because the method is correctly implemented ((7 > 4) is a boolean).
(1) is incorrect because interfaces don't implement anything. (2) is incorrect because classes don't extend interfaces. (5) is incorrect because interface methods are implicitly public, so the methods being implemented must be public.

What will be the output of the program?
try 

    int x = 0; 
    int y = 5 / x; 

catch (Exception e) 
{
    System.out.println("Exception"); 

catch (ArithmeticException ae) 
{
    System.out.println(" Arithmetic Exception"); 

System.out.println("finished");
  • a)
    finished
  • b)
    Exception
  • c)
    Compilation fails.
  • d)
    Arithmetic Exception
Correct answer is option 'C'. Can you explain this answer?

Compilation fails because ArithmeticException has already been caught. ArithmeticException is a subclass of java.lang.Exception, by time the ArithmeticException has been specified it has already been caught by the Exception class.
If ArithmeticException appears before Exception, then the file will compile. When catching exceptions the more specific exceptions must be listed before the more general (the subclasses must be caught before the superclasses).

class A 
{  
    protected int method1(int a, int b) 
    {
        return 0; 
    } 
}
Which is valid in a class that extends class A?
  • a)
    public int method1(int a, int b) {return 0; }
  • b)
    private int method1(int a, int b) { return 0; }
  • c)
    public short method1(int a, int b) { return 0; }
  • d)
    static protected int method1(int a, int b) { return 0; }
Correct answer is option 'A'. Can you explain this answer?

Option A is correct - because the class that extends A is just simply overriding method1.
Option B is wrong - because it can't override as there are less access privileges in the subclass method1.
Option C is wrong - because to override it, the return type needs to be an integer. The different return type means that the method is not overriding but the same argument list means that the method is not overloading. Conflict - compile time error.
Option D is wrong - because you can't override a method and make it a class method i.e. using static.

Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?
  • a)
    java.util.HashSet
  • b)
    java.util.LinkedHashSet
  • c)
    java.util.List
  • d)
    java.util.ArrayList
Correct answer is option 'D'. Can you explain this answer?

All of the collection classes allow you to grow or shrink the size of your collection. ArrayList provides an index to its elements. The newer collection classes tend not to have synchronized methods. Vector is an older implementation of ArrayList functionality and has synchronized methods; it is slower than ArrayList.

Which of the following is FALSE about arrays in Java?
  • a)
    A java array is always an object
  • b)
    Length of array can be changed after creation of array
  • c)
    Arrays in Java are always allocated on heap
  • d)
    None of the above
Correct answer is option 'B'. Can you explain this answer?

In Java, arrays are objects, they have members like length. The length member is final and cannot be changed. All objects are allocated on heap in Java, so arrays are also allocated on heap.

Which two are valid constructors for Thread?
1. Thread(Runnable r, String name)
2. Thread()
3. Thread(int priority)
4. Thread(Runnable r, ThreadGroup g)
5. Thread(Runnable r, int priority)
  • a)
    1 and 3
  • b)
    2 and 4
  • c)
    1 and 2
  • d)
    2 and 5
Correct answer is option 'C'. Can you explain this answer?

(1) and (2) are both valid constructors for Thread.
(3), (4), and (5) are not legal Thread constructors, although (4) is close. If you reverse the arguments in (4), you'd have a valid constructor.

What will be the output of the program?
public class Test 
{  
    public static void aMethod() throws Exception 
    {
        try /* Line 5 */
        {
            throw new Exception(); /* Line 7 */
        } 
        finally /* Line 9 */
        {
            System.out.print("finally "); /* Line 11 */
        } 
    } 
    public static void main(String args[]) 
    {
        try 
        {
            aMethod();  
        } 
        catch (Exception e) /* Line 20 */
        {
            System.out.print("exception "); 
        } 
        System.out.print("finished"); /* Line 24 */
    } 
}
  • a)
    finally
  • b)
    exception finished
  • c)
    finally exception finished
  • d)
    Compilation fails
Correct answer is option 'C'. Can you explain this answer?

This is what happens:
(1) The execution of the try block (line 5) completes abruptly because of the throw statement (line 7).
(2) The exception cannot be assigned to the parameter of any catch clause of the try statement therefore the finally block is executed (line 9) and "finally" is output (line 11).
(3) The finally block completes normally, and then the try statement completes abruptly because of the throw statement (line 7).
(4) The exception is propagated up the call stack and is caught by the catch in the main method (line 20). This prints "exception".
(5) Lastly program execution continues, because the exception has been caught, and "finished" is output (line 24).

Which three are valid method signatures in an interface?
1. private int getArea();
2. public float getVol(float x);
3. public void main(String [] args);
4. public static void main(String [] args);
5. boolean setFlag(Boolean [] test);
  • a)
    1 and 2
  • b)
    2, 3 and 5
  • c)
    3, 4, and 5
  • d)
    2 and 4
Correct answer is option 'B'. Can you explain this answer?

(2), (3), and (5). These are all valid interface method signatures.
(1), is incorrect because an interface method must be public; if it is not explicitly declared public it will be made public implicitly. (4) is incorrect because interface methods cannot be static.

Which of these is a super class of all errors and exceptions in the Java language?
  • a)
    RunTimeExceptions
  • b)
    Throwable
  • c)
    Catchable
  • d)
    None of the above
Correct answer is option 'B'. Can you explain this answer?

All the errors and exception types are subclasses of the built in class Throwable in the java language. Throwable class is the superclass of all errors and exceptions in the Java language. Option (B) is correct.

Which two of the following are legal declarations for nonnested classes and interfaces?
1. final abstract class Test {}
2. public static interface Test {}
3. final public class Test {}
4. protected abstract class Test {}
5. protected interface Test {}
6. abstract public class Test {}
  • a)
    1 and 4
  • b)
    2 and 5
  • c)
    3 and 6
  • d)
    4 and 6
Correct answer is option 'C'. Can you explain this answer?

(3), (6). Both are legal class declarations.
(1) is wrong because a class cannot be abstract and final—there would be no way to use such a class. (2) is wrong because interfaces and classes cannot be marked as static. (4) and (5) are wrong because classes and interfaces cannot be marked as protected.

Which two cause a compiler error?
1. float[ ] f = new float(3);
2. float f2[ ] = new float[ ];
3. float[ ]f1 = new float[3];
4. float f3[ ] = new float[3];
5. float f5[ ] = {1.0f, 2.0f, 2.0f};
  • a)
    2, 4
  • b)
    3, 5
  • c)
    4, 5
  • d)
    1, 2
Correct answer is option 'D'. Can you explain this answer?

(1) causes two compiler errors ( '[' expected and illegal start of expression) because the wrong type of bracket is used, ( ) instead of [ ]. The following is the correct syntax: float[ ] f = new float[3];
(2) causes a compiler error ( '{' expected ) because the array constructor does not specify the number of elements in the array. The following is the correct syntax: float f2[ ] = new float[3];
(3), (4), and (5) compile without error.

Chapter doubts & questions for Java - Mock Tests for EmSAT Achieve 2025 2025 is part of EmSAT Achieve exam preparation. The chapters have been prepared according to the EmSAT Achieve exam syllabus. The Chapter doubts & questions, notes, tests & MCQs are made for EmSAT Achieve 2025 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests here.

Chapter doubts & questions of Java - Mock Tests for EmSAT Achieve 2025 in English & Hindi are available as part of EmSAT Achieve exam. Download more important topics, notes, lectures and mock test series for EmSAT Achieve Exam by signing up for free.

Top Courses EmSAT Achieve