Java Assessment Quiz

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 Harunraja
H
Harunraja
Community Contributor
Quizzes Created: 1 | Total Attempts: 1,708
| Attempts: 1,708 | Questions: 15
Please wait...
Question 1 / 15
0 %
0/100
Score 0/100
1.  Java object oriented programming concepts is/are

Explanation

The correct answer is "All of the above" because Java object-oriented programming concepts include encapsulation, inheritance, and polymorphism. Encapsulation refers to the bundling of data and methods together into a single unit, known as a class. Inheritance allows classes to inherit properties and methods from other classes, creating a hierarchy of classes. Polymorphism allows objects of different classes to be treated as objects of a common superclass, enabling flexibility and code reusability. Therefore, all three concepts are fundamental to Java's object-oriented programming paradigm.

Submit
Please wait...
About This Quiz
Java Assessment Quiz - Quiz

How much do you know about Java? Well, soon, we will find it out when you will take this Java assessment quiz. Java is known as a high-level,... see moreclass-based, object-oriented programming language. The language is designed to possess as few implementation dependencies as possible. It's one of the most used programming languages out there. We hope you like this quiz and learn more about Java as you take it. All the best, programmer! see less

2. What exception can occur in the below java program if we access 5 element in the array that does not exist?
public class TException {

	public static void main(String[] args) {

		try {

			int a[] = { 5, 10, 15, 20 };
			
			System.out.println("Element :" + a[4]);			
		}
		finally{}

	}

}

Explanation

If we try to access the 5th element in the array using the index 4 (a[4]), it will result in an ArrayIndexOutOfBoundsException. This exception occurs when we try to access an index that is outside the bounds of the array. In this case, the array has only 4 elements (indexes 0, 1, 2, and 3), so trying to access the 5th element will throw this exception.

Submit
3. In a class definition, the special method provided to be called to create an instance of that class is known as a/an

Explanation

In a class definition, the special method provided to be called to create an instance of that class is known as a constructor. Constructors are used to initialize the object's state and allocate memory for the object. They are typically defined with the same name as the class and are automatically called when an object of the class is created.

Submit
4. Which polymorphism behavior do you see in the below class?
class Paint {
	// all methods have same name
	public void Color(int x) {
	}

	public void Color(int x, int y) {
	}

	public void Color(int x, int y, int z) {
	}
}

Explanation

The given class demonstrates method overloading. Method overloading occurs when multiple methods in a class have the same name but different parameters. In this case, the "Color" method is defined three times with different numbers of parameters. This allows the class to provide different ways of coloring an object based on the number of arguments passed to the method.

Submit
5. In the below java code, whose “Car” will be called?
class Father {

	public void car() {
		System.out.println("Father's Car");
	}
}

class Son extends Father {

	public void car() {
		System.out.println("Son's Car");
	}
}

public class Sample {

	public static void main(String[] args) {

		Son john = new Son();
		john.car();
	}

}

Explanation

In this Java code, the method `car()` is overridden in the `Son` class, which means that when the `car()` method is called on the object `john`, it will execute the code inside the `car()` method in the `Son` class. Therefore, the output will be "Son's Car".

Submit
6.  What is the meaning of the return data type void?

Explanation

The return data type "void" is used in programming languages to indicate that a function or method does not return any value. It is used when the function or method is intended to perform a task or operation without producing a result that needs to be stored or used elsewhere in the program. In other words, when a function or method has a return type of "void", it means that it does not return any data or memory space for the developers to utilize.

Submit
7. Given the following code snippet; int salaries[]; int index = 0; salaries = new int salaries[4]; while (index < 4) { salaries[index] =  10000; index++; } What is the value of salaries[3]?

Explanation

The code snippet initializes an array called "salaries" with a size of 4. Then, it enters a while loop that iterates as long as the "index" variable is less than 4. Inside the loop, it assigns the value of 10000 to each element of the "salaries" array, starting from index 0 and incrementing the index by 1 each time. Therefore, the value of salaries[3] is 10000.

Submit
8. Which is the correct option about the java interface?

Explanation

The correct option about the Java interface is "All of the above." This means that all the statements mentioned in the options are correct. In Java, interfaces are used to achieve multiple inheritances, meaning a class can implement multiple interfaces. An object of an interface cannot be created directly because interfaces cannot be instantiated. However, a class can implement an interface and create objects of that class. Additionally, an interface can extend another interface, allowing for the creation of a hierarchy of interfaces.

Submit
9. Assume that the value 3929.92 is of type float. How to assign this value after declaring the variable interest of type float?

Explanation

To assign the value 3929.92 to the variable interest of type float, we use the syntax interest = 3929.92f. The "f" at the end of the number indicates that it is a float value.

Submit
10. Direct subclass of Throwable in Java

Explanation

Both A and C are correct because in Java, both Exception and Error are direct subclasses of Throwable. This means that both Exception and Error inherit directly from the Throwable class, making them direct subclasses.

Submit
11. __________ can be used to control the order of certain data structures and collection of objects too.

Explanation

Comparators can be used to control the order of certain data structures and collections of objects. Comparators provide a way to define custom ordering for objects, allowing for sorting and ordering based on specific criteria. By implementing the Comparator interface, developers can define their own comparison logic and apply it to various data structures and collections, giving them control over the ordering of the elements. Therefore, the correct answer is "Comparators".

Submit
12. After the following code fragment, what is the value in fname? String str; int fname; str = "Foolish boy."; fname = str.indexOf("fool");

Explanation

The value in fname is -1 because the method indexOf() returns the index of the first occurrence of the specified substring in the given string. In this case, the substring "fool" is not found in the string "Foolish boy." so the method returns -1.

Submit
13. What is the output of this java program?
public class MemoryJava {

	
	public static void main(String[] args) {
		
		decreaseNumberbyOne(2);
	}
	
	public static void decreaseNumberbyOne(int num){
		
		if(num >= 0){
			
			decreaseNumberbyOne(num -1);
		}
	
		System.out.println("Number:"+num);
	}

}

Explanation

The program recursively calls the `decreaseNumberbyOne` method with `num` decremented by 1 until `num` is less than 0. Then it prints the value of `num`. Since the initial value of `num` is 2, the program will call the method with values 1, 0, and -1 before printing the value of -1. Therefore, the output will be -1, 0, 1, 2.

Submit
14. In what memory area do variable temp and variable card write in main () get stored?
class CreditCard{
	int num;
	
}

public class Bank {

	
	public static void main(String[] args) {
		int temp;
		CreditCard card;
		
	}

}

Explanation

In the given code, the variable "temp" is declared as an integer in the main() method. When a method is called, a new frame is created on the stack to store local variables. So, the variable "temp" will be stored in the stack memory area. Similarly, the variable "card" is declared as an object of the CreditCard class in the main() method. Objects in Java are reference types and the reference variable "card" will also be stored in the stack memory area. Therefore, the correct answer is "Stack, stack".

Submit
15. What is the data type for the number 9.6352?

Explanation

The data type for the number 9.6352 is double. This is because double is a data type that can hold decimal values with a higher precision compared to float.

Submit
View My Results

Quiz Review Timeline (Updated): Jun 17, 2024 +

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

  • Current Version
  • Jun 17, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Oct 05, 2020
    Quiz Created by
    Harunraja
Cancel
  • All
    All (15)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
 Java object oriented programming concepts is/are
What exception can occur in the below java program if we access 5...
In a class definition, the special method provided to be called to...
Which polymorphism behavior do you see in the below class? ...
In the below java code, whose “Car” will be called? ...
 What is the meaning of the return data type void?
Given the following code snippet; ...
Which is the correct option about the java interface?
Assume that the value 3929.92 is of type float. How to assign this...
Direct subclass of Throwable in Java
__________ can be used to control the order of certain data structures...
After the following code fragment, what is the value in fname? ...
What is the output of this java program? ...
In what memory area do variable temp and variable card write in main...
What is the data type for the number 9.6352?
Alert!

Advertisement