Java Basic MCQ
View Answer
A high-level programming language
Key Explanation
- Java is a high-level programming language known for its platform independence and object-oriented nature.
Additional Information
- It was developed by James Gosling at Sun Microsystems and first released in 1995. Java applications run in a virtual machine called the Java Virtual Machine (JVM).
View Answer
string is not a primitive data type in Java
Additional Information
- In Java, "string" is not a primitive data type, but a class representing a sequence of characters.
View Answer
It indicates that a method or variable can be accessed from anywhere
The "public" keyword in Java is used to declare that a class,
method, or variable can be accessed from any other class.
View Answer
It refers to the ability to create multiple instances of classes
Additional Information
- Object-oriented in Java means designing programs around objects that have data and methods, promoting code reusability and modularity.
View Answer
new keyword is used to create a new instance of a class
Additional Information
- The "new" keyword in Java is used to create a new object or instance of a class.
View Answer
It means the method or variable belongs to the class and not to instances of the class
Key Explanation
- The "static" keyword in Java denotes that a method or variable belongs to the class itself, not to instances of the class.
- Learn More about static keyword
int x = 5; int y = 2; int result = x / y; System.out.println(result);
View Answer
The output will be "3" since the division of 5 by 2 results in an integer value.
View Answer
By using the "final" keyword
In Java, constants are defined using the "final" keyword,
making their value immutable.
View Answer
// This is a comment
Additional Information
- Single-line comments in Java are written using "//".
View Answer
To perform conditional execution
Additional Information
- The "if" statement in Java is used to perform conditional execution based on a specified condition.
View Answer
while loop is used when the number of iterations is not known beforehand
Additional Information
- The "while" loop in Java is used when the number of iterations is not known in advance.
View Answer
It terminates the current loop and resumes execution after the loop
Key Explanation
- The "break" statement in Java is used to terminate a loop prematurely.
View Answer
It returns a value from the method
Key Explanation
- The "return" keyword in Java is used to return a value from a method back to the caller.
View Answer
arrays represented in Java as [ ]
Additional Information
- Arrays in Java are represented using square brackets "[]".
View Answer
It specifies the superclass that the current class is inheriting from
Additional Information
- The "extends" keyword in Java is used to establish a subclass that inherits properties and behaviors from a superclass.
View Answer
package-private access modifier allows a variable or method to be accessible only within the same package
Key Explanation
- The "package-private" or default access modifier allows variables or methods to be accessed within the same package but not from outside.
View Answer
Additional Information
- The "try-catch" block in Java is used to handle exceptions and prevent program crashes.
View Answer
By implementing the "Runnable" interface or extending the "Thread" class
In Java, you can create a multi-threaded application by implementing
the "Runnable" interface or extending the "Thread" class.
View Answer
It defines a template for a class to implement
Additional Information
- Interfaces in Java define a contract for classes to implement specific methods, enabling multiple inheritance and achieving abstraction.
View Answer
for (int element : array)
Additional Information
- The correct way to write a for-each loop in Java is by using the syntax "for (int element : array)".
Post your comment