Fresher Drive @ 27th September Java

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Alokanibha
A
Alokanibha
Community Contributor
Quizzes Created: 4 | Total Attempts: 391
| Attempts: 90 | Questions: 21
Please wait...
Question 1 / 21
0 %
0/100
Score 0/100
1. Which class cannot be a subclass in java?

Explanation

A final class in Java cannot be a subclass because the final keyword indicates that the class cannot be extended or inherited by any other class. It is used to prevent further modification or extension of the class. Therefore, a final class is the correct answer as it cannot be a superclass or a parent class for any other class.

Submit
Please wait...
About This Quiz
Fresher Drive @ 27th September Java - Quiz

This Java-focused quiz, titled 'Fresher Drive @ 27th September JAVA', tests knowledge on Java programming concepts including class structures, interfaces, inheritance, and control structures.

Personalize your quiz and earn a certificate with your name on it!
2. Which method must be defined by a class implementing the java.lang.Runnable interface?

Explanation

The method that must be defined by a class implementing the java.lang.Runnable interface is "public void run()". This method is responsible for the actual execution of the thread when it is started. It contains the code that will be run in a separate thread of execution.

Submit
3. What will be the output of the program?class Equals    public static void main(String [] args)    {        int x = 100;        double y = 100.1;        boolean b = (x = y);        System.out.println(b);    } 

Explanation

The program will fail to compile because the expression `(x = y)` is attempting to assign a double value to an int variable, which is not allowed in Java. The assignment operator `=` can only be used to assign values of the same type.

Submit
4. What will be the output of the program?public class Foo{     public static void main(String[] args)    {        try        {            return;        }        finally        {            System.out.println( "Finally" );        }    }} 

Explanation

The output of the program will be "Finally". This is because the code is using a try-finally block. In this case, the try block does not have any code that will be executed, as it only contains a return statement. However, the finally block will always be executed, regardless of whether an exception is thrown or not. Therefore, "Finally" will be printed as the output of the program.

Submit
5. Which is a valid keyword in java?

Explanation

The correct answer is "interface." In Java, "interface" is a valid keyword used to define a collection of abstract methods. It is used to define a contract that a class must implement, specifying the methods that the class should have. It allows for multiple inheritance and is commonly used for achieving abstraction and loose coupling in object-oriented programming.

Submit
6. Which is a valid keyword in java? 

Explanation

The keyword "interface" is a valid keyword in Java. It is used to define a collection of abstract methods that can be implemented by a class. Interfaces provide a way to achieve multiple inheritance in Java and allow classes to have common behavior without actually being related through inheritance.

Submit
7. Which class cannot be a subclass in java?

Explanation

A final class cannot be a subclass in Java because the final keyword is used to restrict the inheritance of a class. When a class is declared as final, it means that it cannot be extended or subclassed by any other class. This is done to prevent any further modifications or extensions to the class, ensuring that its functionality remains intact and unchanged. Therefore, a final class cannot serve as a superclass or be extended by any other class.

Submit
8. What will be the output of the program?public class Foo{     public static void main(String[] args)    {        try        {            return;        }        finally        {            System.out.println( "Finally" );        }    }} 

Explanation

The output of the program will be "Finally". This is because the code inside the finally block will always execute, regardless of whether there is an exception or a return statement in the try block. In this case, the return statement will cause the program to exit the main method, but before doing so, the finally block will be executed and "Finally" will be printed.

Submit
9. Which is a valid declaration within an interface?

Explanation

The correct answer is "Public static short stop = 23". In an interface, all variables are by default public, static, and final. Therefore, it is valid to declare a public static short variable within an interface. The other options provided are not valid declarations within an interface.

Submit
10. Which method executes only once?

Explanation

The init() method executes only once. This method is called when the object is first created and initialized. It is typically used to initialize variables and perform any necessary setup tasks before the object is used. Once the init() method is executed, it will not be called again unless the object is re-initialized.

Submit
11. Which statement is true about a static nested class? 

Explanation

A static nested class is a class that is defined inside another class, but it is marked as static. This means that it can be accessed without creating an instance of the enclosing class. However, because it is static, it does not have access to the nonstatic members (variables and methods) of the enclosing class. Therefore, the statement "It does not have access to nonstatic members of the enclosing class" is true.

Submit
12. Which statement is true about a static nested class?

Explanation

A static nested class is a nested class that is declared with the "static" keyword. This means that it can be accessed without creating an instance of the enclosing class. However, because it is static, it does not have access to nonstatic members (variables and methods) of the enclosing class. It can only access static members of the enclosing class. Therefore, the statement "It does not have access to nonstatic members of the enclosing class" is true.

Submit
13. Why we use array as a parameter of main method?

Explanation

The main method is the entry point of a Java program, and it is typically used to accept command-line arguments. By using an array as a parameter of the main method, we can pass multiple values as command-line arguments to the program. The array allows us to store and access these values easily within the program. Therefore, using an array as a parameter of the main method allows us to store multiple values effectively.

Submit
14. Which three are methods of the Object class?   notify();   notifyAll();   isInterrupted();   synchronized();   interrupt();   wait(long msecs);   sleep(long msecs);   yield(); 

Explanation

The correct answer is 1, 2, 6. The methods notify(), notifyAll(), and wait(long msecs) are methods of the Object class. These methods are used for inter-thread communication and synchronization. The method notify() wakes up a single thread that is waiting on the object's monitor, while notifyAll() wakes up all the threads that are waiting on the object's monitor. The method wait(long msecs) causes the current thread to wait until either another thread invokes the notify() method or a specified amount of time has elapsed.

Submit
15. 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?

Explanation

Default access is the most restrictive access that allows a class to have access to members of another class in the same package. Default access, also known as package-private access, means that the members are accessible only within the same package. It restricts access from classes outside the package, providing a level of encapsulation and preventing unwanted access to the members. Public, private, and protected access modifiers have wider access scopes, allowing access from classes outside the package or subclasses, which may not be desired in this scenario.

Submit
16. What will be the output of the program?for(int i = 0; i < 3; i++){    switch(i)    {        case 0: break;        case 1: System.out.print("one ");        case 2: System.out.print("two ");        case 3: System.out.print("three ");    }System.out.printIn("done");

Explanation

The program uses a switch statement inside a for loop.

In the first iteration of the loop, when i is 0, the case 0 is encountered and the break statement is executed, causing the program to exit the switch statement. The program then prints "done".

In the second iteration, when i is 1, the case 1 is encountered and "one " is printed. Since there is no break statement, the program falls through to the next case. The case 2 is encountered and "two " is printed. The program then exits the switch statement and prints "done".

In the third iteration, when i is 2, the case 2 is encountered and "two " is printed. The program falls through to the next case and encounters case 3, printing "three ". The program then exits the switch statement and prints "done".

Therefore, the output of the program is "one two three two three done".

Submit
17.  Which cause a compiler error? 

Explanation

The line "int [ ][ ] scores = {2,7,6}, {9,3,45};" causes a compiler error because the array initialization is incorrect. In a two-dimensional array, each row should be enclosed in curly braces. So the correct initialization should be "int [ ][ ] scores = {{2,7,6}, {9,3,45}};".

Submit
18. What will be the output?public class Test {            static String  a;            static String  b;            public static void main(String ars[]){                        System.out.print(a+b);            }} 

Explanation

The output will be "nullnull" because both strings "a" and "b" are declared as static variables but not initialized with any values. In Java, when a string variable is not assigned a value, its default value is null. Therefore, when we concatenate two null strings, the result will be "nullnull".

Submit
19. Which cause a compiler error?

Explanation

The line "int [ ][ ] scores = {2,7,6}, {9,3,45};" causes a compiler error because the syntax for initializing a 2D array is incorrect. The correct syntax for initializing a 2D array is "int[][] scores = {{2,7,6}, {9,3,45}};". The correct syntax uses double braces to enclose each row of the 2D array.

Submit
20. What will be the output of the program?class Base{    Base()    {        System.out.print("Base");    }}public class Alpha extends Base{    public static void main(String[] args)    {        new Alpha();        new Base();    }}

Explanation

The output of the program will be "BaseBase".

This is because the class "Alpha" extends the class "Base", which means it inherits all the members of the "Base" class. When the program creates a new instance of "Alpha", it calls the constructor of the "Base" class, which prints "Base". Then, when the program creates a new instance of "Base", it again calls the constructor of the "Base" class, resulting in another "Base" being printed. Therefore, the output is "BaseBase".

Submit
21. Which interface does java.util.Hashtable implement?

Explanation

The correct answer is Java.util.Map. Hashtable in Java implements the Map interface, which means it provides key-value pair storage and retrieval functionality. The Map interface allows you to store and retrieve values based on a unique key. Hashtable is a synchronized implementation of the Map interface, which means it is thread-safe and can be used in multi-threaded environments.

Submit
View My Results

Quiz Review Timeline (Updated): Dec 8, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Dec 08, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 26, 2014
    Quiz Created by
    Alokanibha
Cancel
  • All
    All (21)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Which class cannot be a subclass in java?
Which method must be defined by a class implementing...
What will be the output of the program?class Equals   ...
What will be the output of the program?public class...
Which is a valid keyword in java?
Which is a valid keyword in java? 
Which class cannot be a subclass in java?
What will be the output of the program?public class...
Which is a valid declaration within an interface?
Which method executes only once?
Which statement is true about a static nested class? 
Which statement is true about a static nested class?
Why we use array as a parameter of main method?
Which three are methods of the Object class? ...
You want a class to have access to members of another class in the...
What will be the output of the program?for(int i = 0; i < 3;...
 Which cause a compiler error? 
What will be the output?public class Test...
Which cause a compiler error?
What will be the output of the program?class Base{   ...
Which interface does java.util.Hashtable implement?
Alert!

Advertisement