Skip to main content

Modern Programming Languages MCQs with Answers

Practice important Modern Programming Languages MCQs with answers and explanations.

Chapter: 28
Q521:
Which Java class is the base class for all classes?
A. Object
B. Class
C. System
D. Package
Correct Answer: A
Chapter: 28
Q522:
Which of the following is not allowed in Java class constructors?
A. Multiple constructors with different parameters
B. Constructor overloading
C. Constructors with return types
D. Constructors without return types
Correct Answer: C
Chapter: 28
Q523:
Which of the following is a valid way to initialize a String in Java?
A. String s1 = "hello";
B. String s2 = new String("hello");
C. String s3 = String("hello");
D. String s4 = new String;
Correct Answer: A
Chapter: 28
Q524:
In Java, arrays of which type can be assigned to another array?
A. Primitive arrays
B. Any object arrays
C. Interfaces arrays
D. None of the above
Correct Answer: A
Chapter: 28
Q525:
What does the term "aliasing" refer to in Java?
A. Creating a new instance of an object
B. Assigning the same reference to two variables
C. Creating a copy of an array
D. Overloading a method
Correct Answer: B
Chapter: 28
Q526:
When casting from one primitive type to another in Java, which of the following could cause a loss of information?
A. Implicit conversion
B. Explicit casting
C. Both implicit and explicit conversions
D. None of the above
Correct Answer: B
Chapter: 28
Q527:
If a field is declared `private` in Java, it can be accessed from:
A. Anywhere in the program
B. Only within the class
C. Anywhere in the package
D. Only from subclasses
Correct Answer: B
Chapter: 28
Q528:
Which of the following is true about public fields in Java?
A. They can be accessed anywhere in the program
B. They can only be accessed within the same package
C. They are only accessible from subclasses
D. They cannot be accessed outside the class
Correct Answer: A
Chapter: 28
Q529:
In Java, which method signature is used to declare a method that does not return any value?
A. void methodName()
B. empty methodName()
C. void methodName(void)
D. methodName(void)
Correct Answer: A
Chapter: 28
Q530:
What is the effect of using the `new` keyword in Java?
A. It creates an array
B. It allocates memory for an object
C. It creates a new method
D. It initializes a primitive variable
Correct Answer: B
Chapter: 28
Q531:
Which class type in Java has an object for each primitive type?
A. Wrapper classes
B. Interface classes
C. Abstract classes
D. Primitive classes
Correct Answer: A
Chapter: 28
Q532:
What is the role of the `this` keyword in Java constructors?
A. To access the current object's fields
B. To call another constructor in the same class
C. To return the current object
D. To initialize the object
Correct Answer: A
Chapter: 28
Q533:
In Java, which of the following is true about static methods?
A. They can access instance variables
B. They cannot access instance variables
C. They must have a return type
D. They can only be called from a subclass
Correct Answer: B
Chapter: 29
Q534:
What is required to specify a package in a Java file?
A. package name
B. package declaration
C. package keyword
D. package statement
Correct Answer: A
Chapter: 29
Q535:
Which keyword prevents a class from being extended in Java?
A. final
B. abstract
C. protected
D. private
Correct Answer: A
Chapter: 29
Q536:
In Java, how can you access public classes in another package?
A. package-name.class-name
B. package-name.method-name
C. class-name.method-name
D. method-name.class-name
Correct Answer: A
Chapter: 29
Q537:
What is the purpose of the 'import' statement in Java?
A. It allows access to non-public classes
B. It enables code optimization
C. It imports classes from another package
D. It imports classes into the main method
Correct Answer: C
Chapter: 29
Q538:
Which method must be defined in a subclass to override a method in Java?
A. The constructor
B. The method with the same name
C. Any method
D. The method with different arguments
Correct Answer: B
Chapter: 29
Q539:
What is the purpose of the 'final' keyword in Java?
A. It makes a method accessible from any class
B. It makes a method not overrideable
C. It allows inheritance
D. It prevents class instantiation
Correct Answer: B
Chapter: 29
Q540:
What does inheritance in Java allow?
A. Access to private fields
B. Implementation of an interface
C. Sharing fields and methods between classes
D. Creation of abstract methods
Correct Answer: C

Test Your Knowledge

Take a timed quiz on Modern Programming Languages

🚀 Start Quiz Now