Question 1
EasyWhich method is the entry point of a Java application?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Programming Languages
Which method is the entry point of a Java application?
void run(String args)
static int main()
public static void main(String[] args)
public void start()
Answer: C
The JVM looks for this exact signature to start the program.
Which of these is NOT a primitive type in Java?
boolean
int
char
String
Answer: D
String is a class (a reference type). Java has eight primitives: byte, short, int, long, float, double, char and boolean.
What is the size of an int in Java?
32 bits
16 bits
64 bits
It depends on the platform
Answer: A
Java fixes primitive sizes on every platform: int is always 32 bits.
What does the JVM do?
Compiles C code
Runs Java bytecode on a particular platform
Edits Java source files
Stores Java libraries online
Answer: B
javac compiles .java files to .class bytecode, which any JVM can run — 'write once, run anywhere'.
Which keyword is used to inherit from a class in Java?
implements
extends
inherits
super
Answer: B
class B extends A. implements is used for interfaces.
What is the output of this program?
public class Main {
public static void main(String[] args) {
String s = "Hello " + "World";
System.out.println(s);
}
}
Hello World
Hello+World
Answer: A
What is the default value of an int field (instance variable) in Java?
1
0
null
Garbage
Answer: B
Fields get defaults (0, false, null). Local variables have no default and must be assigned before use.
In Java, what is bytecode?
The instructions in a .class file, which the JVM runs
Machine code for one specific CPU
The Java source code
A type of comment
Answer: A
The compiler (javac) turns source code into bytecode, which any JVM can run.
Which keyword makes a Java variable a constant that cannot be reassigned?
final
const
constant
static
Answer: A
const is reserved in Java but not used; final is the keyword for constants.
In Java, what is 7 / 2 when both numbers are ints?
3
4
3.5
3.0
Answer: A
Integer division drops the fractional part.
HelloWorld
Error