Assessment Of Java Training

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 AnandVR
A
AnandVR
Community Contributor
Quizzes Created: 1 | Total Attempts: 446
| Attempts: 446 | Questions: 50
Please wait...
Question 1 / 50
0 %
0/100
Score 0/100
1. What is the entry point of java Execution?

Explanation

The correct answer is "public static void main(String args[])". In Java, the main method serves as the entry point for the execution of a program. It is a public method, as it needs to be accessible from outside the class. The "static" keyword is used to allow the method to be called without creating an instance of the class. The return type is "void", indicating that the main method does not return any value. The method takes an array of strings (args) as a parameter, which allows command-line arguments to be passed to the program.

Submit
Please wait...
About This Quiz
Java Quizzes & Trivia

This quiz assesses knowledge in Java programming, focusing on interface definitions, array creation, inheritance, class subclassing, method declaration, and types of inheritance. It's designed for learners to validate their Java training effectively.

Personalize your quiz and earn a certificate with your name on it!
2. The finally block is executed when an exception is thrown, even if no catch matches it.

Explanation

The finally block in Java is used to execute a set of statements regardless of whether an exception is thrown or not. It ensures that certain code is always executed, even if an exception occurs. In this case, the correct answer is "Yes" because the finally block will be executed even if no catch block matches the thrown exception. This is important for tasks such as closing resources or releasing locks, which need to be done regardless of whether an exception occurs.

Submit
3. What is the output of following code int x[]={1,2,3,4}; Sytem.out.println(" Index at 4 is "+x[4]);

Explanation

The code is trying to access the element at index 4 of the array "x", but the array only has indices 0, 1, 2, and 3. Therefore, it will throw an IndexOutOfBoundsException.

Submit
4. Which of the java classes that cannot be subclassed?

Explanation

A final class in Java cannot be subclassed because it is declared with the "final" keyword, which means it cannot be extended by any other class. This is useful when you want to prevent any further modification or extension of a class, ensuring that its implementation remains unchanged. Therefore, a final class is the correct answer as it cannot be subclassed.

Submit
5. Is multiple Inheritance is supported in case of Interfaces?

Explanation

Multiple inheritance is supported in case of interfaces. In object-oriented programming, multiple inheritance refers to a class inheriting properties and behaviors from multiple parent classes. However, some programming languages do not support multiple inheritance for classes, as it can lead to complexity and ambiguity. Interfaces, on the other hand, provide a way to achieve multiple inheritance in a controlled manner. A class can implement multiple interfaces, allowing it to inherit and define multiple sets of properties and behaviors. Therefore, the correct answer is Yes.

Submit
6. Which is the Collection Framework  class to store key and value?

Explanation

HashMap is the correct answer because it is a class in the Collection Framework that allows storing key-value pairs. It implements the Map interface and provides efficient retrieval and storage of elements based on their keys. HashMap uses a hash table data structure to store the key-value pairs, allowing for fast access and retrieval of elements.

Submit
7. In which memory area of JVM objects will be created?

Explanation

Objects in Java are created in the Heap Memory area of the JVM. The Heap Memory is a region of memory used for dynamic memory allocation, where objects are stored. It is a shared memory area accessible by all threads in a Java application. The JVM automatically manages the allocation and deallocation of memory in the Heap, making it suitable for creating and storing objects. The other memory areas mentioned, such as Stack Memory and Method Area, have different purposes and are not used for object creation.

Submit
8. Which type of inheritance is not supported by java?

Explanation

Java does not support multiple inheritance, which means a class cannot inherit from multiple classes at the same time. This is because multiple inheritance can lead to complex situations such as diamond problem, where a class inherits from two classes that have a common superclass. To avoid such complications, Java uses interfaces to achieve multiple inheritance-like behavior, where a class can implement multiple interfaces but can only extend one class.

Submit
9. What is the base class of all Java classes?

Explanation

The base class of all Java classes is the Object class. This class is at the top of the Java class hierarchy and is implicitly inherited by all other classes in Java. It provides a set of methods that are common to all objects, such as toString(), equals(), and hashCode(). By inheriting from the Object class, all Java classes have access to these methods and can override them as needed.

Submit
10. Can interfaces have method implementation?

Explanation

Interfaces in most programming languages cannot have method implementations. By default, all methods declared in an interface are abstract methods, meaning they do not have a body. This is because interfaces are meant to define a contract or a set of methods that implementing classes must implement. The actual implementation of these methods is left to the classes that implement the interface. Therefore, the correct answer is that interfaces cannot have method implementations.

Submit
11. Which keyword is used to inherit class?

Explanation

The keyword "extends" is used to inherit a class in object-oriented programming. Inheritance allows a class to inherit the properties and methods of another class, known as the superclass or parent class. By using the "extends" keyword, a subclass or child class can inherit all the non-private members of the superclass. This allows for code reuse, as the subclass can add additional functionality or override existing methods from the superclass.

Submit
12. If there is no memory in Heap,what will happen on before next "new" Statement execution

Explanation

When there is no memory available in the Heap, the garbage collection process will run. If there is enough memory available after garbage collection, a new object will be created. However, if there is still not enough memory available, an OutOfMemoryError will be thrown.

Submit
13. Java final methods cannot be overridden but overloaded?

Explanation

In Java, the final keyword is used to indicate that a method cannot be overridden in a subclass. This means that once a method is declared as final in a superclass, it cannot be modified or overridden in any of its subclasses. However, final methods can still be overloaded in the same class or in its subclasses. Overloading refers to having multiple methods with the same name but different parameters in the same class or its subclasses. Therefore, the statement "Java final methods cannot be overridden but overloaded" is true.

Submit
14. What is the output of below code snipet?    final ArrayList list=new ArrayList();            list=new LinkedList()

Explanation

The code snippet will result in a compilation error. This is because the variable "list" is declared as final, which means it cannot be reassigned to a different object. In the code, after declaring "list" as an ArrayList, it is then being reassigned to a LinkedList, which is not allowed due to the final keyword.

Submit
15. Which is right way to creating an array of integer in java?

Explanation

The correct way to create an array of integers in Java is by using the syntax "int[] javaArray = new int[10];". This declares an integer array named "javaArray" with a length of 10. The "int[]" specifies that it is an array of integers, and "new int[10]" creates a new array object with 10 elements.

Submit
16. An abstract class should have methods all declared abstract?

Explanation

No, an abstract class can have both abstract methods and non-abstract methods. Abstract methods are declared without any implementation and must be implemented by the concrete subclasses. Non-abstract methods in an abstract class can have their own implementation and can be used by the subclasses. This allows for code reuse and provides a common base for the subclasses to inherit from.

Submit
17. What is the size of int in java 

Explanation

The size of an int in Java is 4 bytes. In Java, the int data type is a 32-bit signed integer, which means it can hold values ranging from -2,147,483,648 to 2,147,483,647. The size of an int is fixed and does not depend on the platform or operating system being used.

Submit
18. In the below code which can directly access and change the value of the variable id? package com.cisco.mycompany;   public class Company  {     private int id = 100; }

Explanation

The variable "id" in the code is declared as private, which means it can only be accessed and modified within the same class. Therefore, only the Company class itself can directly access and change the value of the variable "id".

Submit
19. Which of the following class is not part of java Collection Framework

Explanation

The class "String" is not part of the Java Collection Framework because it does not implement the Collection interface or any of its subinterfaces (List, Set, Queue). The Java Collection Framework is a set of classes and interfaces that provide implementations of common data structures like lists, sets, and maps. While String is a commonly used class in Java for representing textual data, it is not a collection class and does not provide methods for adding, removing, or manipulating elements like the other options (Vector, ArrayList, HashMap) do.

Submit
20. Which is the base class in Exception hierarchy?

Explanation

The base class in the Exception hierarchy is Throwable. This class is the superclass for all exceptions and errors in Java. It provides methods and fields for handling and reporting exceptions and errors. The Exception and RuntimeException classes are subclasses of Throwable, but they are not the base class.

Submit
21.  The finalize() method present in Object class is called just prior to

Explanation

The finalize() method in the Object class is called before garbage collection. This means that when an object is no longer referenced and is eligible for garbage collection, the finalize() method is invoked just before it is actually collected by the garbage collector. This method can be used to perform any necessary cleanup or resource releasing tasks before the object is destroyed.

Submit
22. )what is the output of below code snippet public class Sample {   public static void outcome(int a) { System.out.print("int "); }   public static void outcome(long a) { System.out.print("long "); }   public static void main(String[] args) { short shortVar = 1; long longVar = 109002; outcome(shortVar); outcome(longVar); outcome(1); } }

Explanation

The code snippet defines three overloaded methods named "outcome". The first method takes an int parameter, the second method takes a long parameter, and the third method takes an int parameter. In the main method, the "outcome" method is called three times with different arguments. The first call passes a short variable, which is automatically promoted to an int, so the first method is called and "int " is printed. The second call passes a long variable, so the second method is called and "long " is printed. The third call passes an int literal, so the third method is called and "int " is printed. Therefore, the output is "int long int".

Submit
23. Given the below class definitions   class Base { void display () { System.out.println("Base"); } } class Derived extends Base { void display () { System.out.println("Derived"); } } and objects Base b = new Base(); Derived d = new Derived(); Base bd = new Derived(); then the print statements System.out.print(b.display() + " "); System.out.print(d.display() + " "); System.out.print(bd.display() + " "); System.out.println(); will display:

Explanation

The print statements will display "Base Derived Derived" because when the display() method is called on the object b, it prints "Base". When the display() method is called on the object d, it prints "Derived". When the display() method is called on the object bd, it is still a Derived object, so it prints "Derived".

Submit
24. Given the code. What is the result if NullPointerException occurs at line 2? 1.      try { 2.          //some code goes here 3.      } 4.      catch (NullPointerException ne) { 5.          System.out.print("1 "); 6.      } 7.      catch (RuntimeException re) { 8.          System.out.print("2 "); 9.      } 10.     finally { 11.         System.out.print("3"); 12.     }

Explanation

If a NullPointerException occurs at line 2, the catch block at line 4 will be executed. This catch block will print "1 " to the console. After that, the finally block at line 10 will be executed and it will print "3" to the console. So the result will be "1 3".

Submit
25. What is the output of following code    int a=10;  int b=10;  System.out.println("The sum of a and b is "+a+b);

Explanation

The output of the code is "The sum of a and b is 1010" because the code uses the concatenation operator (+) to combine the string "The sum of a and b is " with the values of variables a and b, which are both integers. When concatenating a string with an integer, the integer is converted to a string. In this case, the code first concatenates "The sum of a and b is " with the value of a (10), resulting in "The sum of a and b is 10". Then it concatenates this string with the value of b (10), resulting in "The sum of a and b is 1010".

Submit
26. What is the default date type  for whole Numbers and Decimal Numbers?

Explanation

The default data type for whole numbers and decimal numbers is "int double".

Submit
27. Which of the following is true about class defination in a file 

Explanation

In Java, it is possible to define multiple classes in a single file. However, there can be only one public class in that file, and the name of the public class must match the name of the file. Therefore, all of the given statements are true about class definition in a file.

Submit
28. Given the below code. What is the result?    class Test    {        public static void main(String args[]) {                 String str = "null";                 if (str == null) {                         System.out.print("1");                 } else if (str.length() == 0) {                         System.out.print("2");                 } else {                         System.out.print("3");                 }         }   }

Explanation

The code initializes a String variable "str" with the value "null". The if statement checks if "str" is equal to null, which is true. Therefore, the code inside the if block is executed, and "1" is not printed. The else if statement checks if the length of "str" is equal to 0, which is false. Therefore, the code inside the else if block is not executed, and "2" is not printed. Since none of the previous conditions are met, the code inside the else block is executed, and "3" is printed. Therefore, the correct answer is "3" is printed.

Submit
29. Class Test { public static void main(String[] args){   Object obj;   obj.toString(); } }

Explanation

In the given code, a NullPointerException will occur. This is because the variable "obj" is declared but not initialized with any object. When the method "toString()" is called on an uninitialized object, it will throw a NullPointerException.

Submit
30. Given the code. What is the result after the class TryMe execution? class A {     public void doA() {         B b = new B();         b.dobB();         System.out.print("doA");     } }   class B {     public void dobB() {         C c = new C();         c.doC();         System.out.print("doB");     } }   class C {     public void doC() {         if (true)             throw new NullPointerException();         System.out.print("doC");     } }   public class TryMe {       public static void main(String args[]) {         try {             A a = new A();             a.doA();         } catch (Exception ex) {             System.out.print("error");         }     } }

Explanation

The code throws a NullPointerException in the doC() method of class C because the if statement condition is always true. This exception is caught in the catch block in the main method of class TryMe. Therefore, the program prints "error" as the result.

Submit
31. Can we declare abstract static method?

Explanation

No, we cannot declare an abstract static method. Abstract methods are meant to be overridden in the subclass, but static methods belong to the class itself and cannot be overridden. The combination of abstract and static modifiers is not allowed in Java. Abstract methods must be declared in an abstract class or interface, and they require the subclass to provide an implementation.

Submit
32. Given the code. What is the result? class Vehicle {     public void printSound() {         System.out.print("vehicle");     } }   class Car extends Vehicle {     public void printSound() {         System.out.print("car");     } }   class Bike extends Vehicle {     public void printSound() {         System.out.print("bike");     } }   public class Test {     public static void main(String[] args) {         Vehicle v = new Car();         Bike b = (Bike) v;                  v.printSound();         b.printSound();     }    }

Explanation

In the given code, a Vehicle object v is created and assigned a new Car object. Then, a Bike object b is created by casting v to a Bike object. However, since v is actually a Car object, it cannot be cast to a Bike object. This results in a ClassCastException being thrown at runtime.

Submit
33. What is the output of below code snippet public class Test {   static{ System.out.println("1"); } { System.out.println("3"); }       public static void main(String[] args) {     System.out.println("2");     }      }

Explanation

The code snippet includes a static block and an instance block. The static block is executed before the main method, so "1" is printed first. The instance block is executed each time an object of the class is created, so "3" is printed next. Finally, the main method is executed, printing "2". Therefore, the output of the code snippet is "1 and 2".

Submit
34. What is the output of the below code snippet   public class Test {     public static void main(String[] args) {          String s1="ABC";     String s2="ABC";         String s3=new String("ABC");         System.out.println((s1==s2)+" "+(s1.equals(s3)));         }    }

Explanation

The output of the code snippet will be "true true" because the == operator checks for reference equality, and since s1 and s2 are both pointing to the same string literal "ABC", they have the same reference. The equals() method, on the other hand, checks for content equality, and since s1 and s3 have the same content "ABC", the result of s1.equals(s3) is also true.

Submit
35. Which is the valid declarations within an interface definition?

Explanation

Option A is correct. A public access modifier is acceptable. The method prototypes in an interface are all abstract by virtue of their declaration, and should not be declared abstract.
Option B is wrong. The final modifier means that this method cannot be constructed in a subclass. A final method cannot be abstract.
Option C is wrong. static is concerned with the class and not an instance.

Submit
36. Which of the following are primitive types?

Explanation

The primitive types in programming refer to the basic data types that are built-in and not derived from any other type. In this case, the correct answer is "byte" because it is a primitive type in many programming languages, including Java. String, Integer, and Float are not primitive types, as they are classes or objects that provide additional functionality beyond basic data storage.

Submit
37. Which of the follwing exe in java bin folder is java virtual machine that will ne used to launch java program

Explanation

The correct answer is "java" because it is the executable file in the Java bin folder that is responsible for launching Java programs. The "java" command is used to start the Java Virtual Machine (JVM), which then executes the bytecode of the Java program. The other options listed are not responsible for launching Java programs. "javac" is the Java compiler, "javah" is used for generating C header files, and "javadoc" is used for generating documentation from Java source code.

Submit
38. Which is the Object class method to be overriden to display meaningfull representation of Object state?

Explanation

The correct answer is toString(). This method is used to return a string representation of an object. By overriding this method, we can provide a meaningful representation of the object's state. This can be useful for debugging purposes or for displaying the object in a user-friendly way.

Submit
39. Given interface declaration interface Base  {     boolean m1 ();     byte m2(short s); } which code fragment will compile?

Explanation

The correct answer is "abstract class Class2 implements Base { public boolean m1() { return (7 > 4); } }". This code fragment will compile because it is implementing the interface Base and providing an implementation for the m1() method. The implementation returns a boolean value based on the condition (7 > 4).

Submit
40. Which of the following are the new type in Java

Explanation

In Java, both classes and interfaces are considered new types. A class is a blueprint for creating objects, while an interface is a collection of abstract methods that can be implemented by classes. Both classes and interfaces are used to define the structure and behavior of objects in Java. Therefore, the correct answer is "Both Class and Interface."

Submit
41. Is Floating point operations is supported in MCHAI JVM(CISCO)

Explanation

The explanation for the answer "No" is that the MCHAI JVM (Cisco) does not support floating point operations. This means that any calculations or operations involving floating point numbers cannot be performed in this JVM.

Submit
42. In the below code snippet in which memory area below objects s1 and o1 are created public class Test { String s1 =new String("XYZ");     public static void main(String[] args) {     Object o1=new Object();;     }    }

Explanation

In the given code snippet, the memory area below the objects s1 and o1 are created in the heap. This is because both the String object s1 and the Object object o1 are created using the "new" keyword, which allocates memory in the heap. The stack is used for method calls and local variables, but in this code snippet, there are no method calls or local variables declared. Therefore, the memory area below the objects s1 and o1 is created in the heap.

Submit
43. Which of the following is wrapper classes in java

Explanation

Wrapper classes in Java are classes that encapsulate primitive data types and provide useful methods and functionalities. They allow primitive data types to be treated as objects. In this case, Integer, Float, and Byte are all examples of wrapper classes in Java. They provide additional methods and functionalities that are not available with primitive data types, such as parsing, converting, and performing mathematical operations. String, on the other hand, is not a wrapper class as it is a class that represents a sequence of characters and is used to manipulate and store textual data.

Submit
44. Which of following is true about Heapmemory configaration 

Explanation

The correct answer is "can be only changed before JVM starts." This means that the configuration of the heap memory in a JVM can only be modified before the JVM is launched. Once the JVM has started, the heap memory configuration cannot be changed dynamically.

Submit
45. What is the output of below code snippet? import java.util.HashMap; import java.util.Map;     public class Test {     public static void main(String[] args) {          Map map=new HashMap();     map.put(new Integer(1), "one");     map.put(new Integer(1), "two");     System.out.println(map.get(new Integer(1)));      }    }

Explanation

The code snippet creates a HashMap object called "map" and adds two key-value pairs to it. Both keys are Integer objects with the value 1, but they are different instances. The first key-value pair adds the key 1 and the value "one" to the map, and the second key-value pair adds the key 1 and the value "two" to the map. When the code calls the get() method on the map with a new Integer object with the value 1 as the argument, it will retrieve the value associated with that key, which is "two". Therefore, the output of the code snippet will be "two".

Submit
46. What is the output of below code snippet?  Map map=new HashMap();  String s1=new String("Key1");  String s2=new String("Key1");  map.put(s1,"Value1");  System.out.println(map.get(s2));

Explanation

The output of the code snippet will be "Value1". This is because even though the two String objects, s1 and s2, have the same value, they are still different objects in memory. When we use s1 as the key to put a value in the map, it gets stored in the map. When we try to retrieve the value using s2 as the key, it will still return the value "Value1" because the map uses the equals() method to compare keys, not the == operator.

Submit
47. Which are the  methods to be overriden to insert user defined type in hashmap?

Explanation

The correct answer is hashCode() and equals(Object obj). These methods need to be overridden in order to insert a user-defined type into a HashMap. The hashCode() method is used to generate a unique hash code for the object, which is used by the HashMap to determine the bucket where the object should be stored. The equals(Object obj) method is used to compare two objects for equality, which is necessary for the HashMap to check if an object already exists in the map. By overriding these methods, the user-defined type can be properly inserted and retrieved from the HashMap.

Submit
48. Which of the following statements correctly describes the relation between an object and the instance variable it stores?

Explanation

Each new object has its own distinctive set of instance variables because each object is created from a class blueprint and has its own unique state. Each object has a copy of the instance variables of its class because instance variables are defined within a class and each object of that class will have its own copy of those variables. The instance variables of each object are separate from the variables of other objects because they are stored within the memory space allocated to each individual object and can be accessed and modified independently.

Submit
49. What is the output of below code snippet  public class Test {     public static void main(String[] args) {     final int x;     x=11;     final String str=new String("ABC");     str.toLowerCase();     System.out.println(str);         }    }

Explanation

The code snippet declares a final variable "str" of type String and assigns it the value "ABC". The method "toLowerCase()" is called on the string object, but since strings are immutable in Java, the method does not modify the original string. Therefore, the output of the code will be "ABC".

Submit
50. Which of the following statements accurately describe the use of access modifiers(private,public,protected) within a class definition?

Explanation

Access modifiers (private, public, protected) can be applied to both data and methods within a class definition. They must precede a class's data variables or methods and can appear in any order. However, there is no requirement that they must be applied to data variables first and then to methods.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 20, 2023 +

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

  • Current Version
  • Mar 20, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 21, 2013
    Quiz Created by
    AnandVR
Cancel
  • All
    All (50)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What is the entry point of java Execution?
The finally block is executed when an exception is thrown, even if no...
What is the output of following code ...
Which of the java classes that cannot be subclassed?
Is multiple Inheritance is supported in case of Interfaces?
Which is the Collection Framework  class to store key and value?
In which memory area of JVM objects will be created?
Which type of inheritance is not supported by java?
What is the base class of all Java classes?
Can interfaces have method implementation?
Which keyword is used to inherit class?
If there is no memory in Heap,what will happen on before next...
Java final methods cannot be overridden but overloaded?
What is the output of below code snipet? ...
Which is right way to creating an array of integer in java?
An abstract class should have methods all declared abstract?
What is the size of int in java 
In the below code which can directly access and change the value of...
Which of the following class is not part of java Collection Framework
Which is the base class in Exception hierarchy?
 The finalize() method present in Object class is called just...
)what is the output of below code snippet ...
Given the below class definitions ...
Given the code. What is the result if NullPointerException occurs at...
What is the output of following code ...
What is the default date type  for whole Numbers and Decimal...
Which of the following is true about class defination in a file 
Given the below code. What is the result? ...
Class Test ...
Given the code. What is the result after the class TryMe execution? ...
Can we declare abstract static method?
Given the code. What is the result? ...
What is the output of below code snippet ...
What is the output of the below code snippet ...
Which is the valid declarations within an interface definition?
Which of the following are primitive types?
Which of the follwing exe in java bin folder is java virtual machine...
Which is the Object class method to be overriden to display...
Given interface declaration ...
Which of the following are the new type in Java
Is Floating point operations is supported in MCHAI JVM(CISCO)
In the below code snippet in which memory area below objects s1 and o1...
Which of the following is wrapper classes in java
Which of following is true about Heapmemory configaration 
What is the output of below code snippet? ...
What is the output of below code snippet? ...
Which are the  methods to be overriden to insert user defined...
Which of the following statements correctly describes the relation...
What is the output of below code snippet ...
Which of the following statements accurately describe the use of...
Alert!

Advertisement