Skip to content

Java Fundamentals MCQs (Multiple Choice Questions)

Advertisement

Java, one of the most widely used programming languages, offers a versatile platform for developing a range of applications, from web to mobile to enterprise solutions. As beginners embark on their journey to master Java, understanding its basics becomes paramount. To aid in this educational pursuit, we present a comprehensive set of 75+ multiple-choice questions (MCQs) covering the fundamental concepts of Java programming. These questions span topics such as data types, control structures, object-oriented programming (OOP) principles, and much more. Accompanied by correct answers and concise explanations, this collection aims to reinforce learning and clarify common misconceptions, providing a solid foundation in Java basics.

Q1 What is the correct syntax for declaring a new array in Java?


Q2 Which of the following is not a primitive data type in Java?


Q3 What is the output of the following Java code?


int x = 5;
int y = 10;
int z = x + y;
System.out.println(z);


Q4 What is the purpose of the “final” keyword in Java?


Q5 Which of the following is not a valid looping construct in Java?


Q6 What is the output of the following Java code?


int x = 10;
int y = 20;
if (x > y) {
  System.out.println("x is greater than y");
} else if (x < y) {
  System.out.println("x is less than y");
} else {
  System.out.println("x is equal to y");
}


Q7 Which of the following data types is used to store a single character in Java?


Q8 What does JVM stand for?


Q9 Which keyword is used to create a class in Java?


Q10 Which method is called when a Java program starts?


Q11 What is the size of a char in Java?


Q12 Which of the following is a valid declaration of a String?


Q13 Which operator is used to compare two values?


Q14 What is the result of the expression 9 % 2?


Q15 Which of the following is a loop construct in Java?


Q16 What is encapsulation in Java?


Q17 Which keyword is used to inherit a class in Java?


Q18 How many constructors can a class have in Java?


Q19 Which of these access specifiers can be used for an interface?


Q20 What is the default value of a local variable in Java?


Q21 What is the output of?


System.out.println(10+20+"Hello"+10+20);


Q22 Which keyword is used to access the superclass in Java?


Q23 What does the expression evaluate to?


boolean isTrue = !false;


Q24 What is polymorphism in Java?


Q25 What will be the output of the following Java code snippet?


int a = 10;
int b = ++a + a++ + --a + a--;
System.out.println(b);


Q26 Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but is not synchronized?


Q27 What will be the result of compiling and running the following Java code snippet?


public class Test {
    public static void main(String[] args) {
        int x = 10;
        int y = new Test().change(x);
        System.out.print(x + y);
    }
    int change(int x) {
        x = 12;
        return x;
    }
}


Q28 Which of the following is true about a final class in Java?


Q29 Which interface does java.util.Hashtable implement?


Q30 What is the default value of a static variable of type int?


Q31 Which method must be implemented by all threads in Java?


Q32 Which of these is used to make an object of a class serializable in Java?


Q33 Which keyword is used to prevent method overriding in Java?


Q34 How can you access the first element of an array named arr?


Q35 Which of these is a valid Java identifier?


Q36 Which class in Java is used for parsing strings to numbers?


Q37 What is the size of an int in Java?


Q38 Which exception is thrown when trying to access a class for which a definition is not found?


Q39 In Java, which operator is used for instance comparison?


Q40 What does the transient keyword in Java do?


Q41 Which of the following is true about the switch statement in Java?


Q42 What will this code print?


System.out.println('100');


Q43 Which of the following is not a wrapper class in Java?


Q44 How do you ensure that a resource is automatically closed at the end of the statement block?


Q45 What is the purpose of the super keyword in Java?


Q46 Which of these collections is ordered?


Q47 What will be the result of compiling and running the following code?


int a = null;
System.out.println(a);


Q48 Which of these access specifiers allows visibility only within the same package and subclasses?


Q49 In Java, how do you declare a variable that cannot be modified after it is initialized?


Q50 What is autoboxing in Java?


Q51 Which of the following is true about the enum type in Java?


Q52 What does the static keyword in Java indicate?


Q53 Which of the following is not a Java control statement?


Q54 In Java, what is method overloading?


Q55 In Java, which of the following is the correct way to declare a variable of type float?


Q56 Which of the following is true about the static keyword in Java?


Q57 Which of the following loop constructs will run at least once?


Q58 What is the result of 10 >> 2 in Java?


Q59 What is the correct syntax for defining an interface in Java?


Q60 Which method is used to compare two strings for equality in Java?


Q61 In Java, which keyword is used to reference the current object?


Q62 Which of these is not a visibility modifier in Java?


Q63 What does the finally block in a try-catch structure do?


Q64 What is the base class of all classes in Java?


Q65 Which of these is a correct way to allocate memory to an array in Java?


Q66 What does the abstract keyword mean in Java?


Q67 Which of the following is true about package in Java?


Q68 What is the output of the following snippet?


String s1 = "Java";
String s2 = new String("Java");
System.out.println(s1 == s2);


Q69 In Java, constructor overloading:


Q70 Which of the following is not an OOP principle?


Q71 The continue statement in Java:


Q72 What will be the output of the following code?


for(int i=0; i<5; i++){
    if(i==3)
        break;
    System.out.print(i + " ");
}


Q73 An instance of which of the following can be changed after it is created?


Q74 What is the scope of package-level access modifier in Java?


Q75 Which of these is not a Java feature?


Q76 The finalize() method in Java is called:


Q77 Which of these is a valid declaration of a byte array in Java?


Q78 Which keyword is used for synchronizing a block of code in Java?


Q79 Which exception is thrown when accessing an out-of-bound index of an array in Java?


Navigating through the basics of Java with these 50 MCQs offers learners an opportunity to test their knowledge and gain a deeper understanding of the language's core principles. Each question, along with its explanation, serves as a building block in the learning process, addressing key concepts from syntax to OOP. This resource is designed not only to challenge but also to enlighten, ensuring that beginners can progress in their Java programming journey with confidence. Whether you're preparing for an exam, brushing up on your skills, or just starting out, these questions can be a valuable tool in your study arsenal, helping to lay a strong foundation for more advanced Java programming topics.

Rahul

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top