- Aclass, if, void, long, Int, continue
- Bgoto, instanceof, native, finally, default, throws
- Ctry, virtual, throw, final, volatile, transient
- D strictfp, constant, super, implements, do
Time Taken:
Correct Answer:
Wrong Answer:
Percentage: %
All the words in option B are among the 49 Java keywords. Although goto reserved as a keyword in Java, goto is not used and has no function.
Option A is wrong because the keyword for the primitive int starts with a lowercase i.
Option C is wrong because "virtual" is a keyword in C++, but not Java.
Option D is wrong because "constant" is not a keyword. Constants in Java are marked static and final.
Option E is wrong because "include" is a keyword in C, but not in Java.
(1), (2), and (4) are legal array declarations. With an array declaration, you can place the brackets to the right or left of the identifier. Option A looks strange, but it's perfectly legal to split the brackets in a multidimensional array, and place them on both sides of the identifier. Although coding this way would only annoy your fellow programmers, for the exam, you need to know it's legal.
(3) and (5) are wrong because you can't declare an array with a size. The size is only needed when the array is actually instantiated (and the JVM needs to know how much space to allocate for the array, based on the type of array and the size).
(1), (3), and (6) are correct. char c1 = 064770; is an octal representation of the integer value 27128, which is legal because it fits into an unsigned 16-bit integer. char c3 = 0xbeef; is a hexadecimal representation of the integer value 48879, which fits into an unsigned 16-bit integer. char c6 = '\uface'; is a Unicode representation of a character.
char c2 = 'face'; is wrong because you can't put more than one character in a char literal. The only other acceptable char literal that can go between single quotes is a Unicode value, and Unicode literals must always start with a '\u'.
char c4 = \u0022; is wrong because the single quotes are missing.
char c5 = '\iface'; is wrong because it appears to be a Unicode representation (notice the backslash), but starts with '\i' rather than '\u'.
A char is really a 16-bit integer behind the scenes, so it supports 216 (from 0 to 65535) values.
Option D is correct. A runtime error will occur owning to the main method of the code fragment not being declared static:
Exception in thread "main" java.lang.NoSuchMethodError: main
The Java Language Specification clearly states: "The main method must be declared public, static, and void. It must accept a single argument that is an array of strings."
The loops use the array sizes (length).
It produces 11 lines of output as given below.
D:\Java>javac Test.java D:\Java>java Test size = 1 size = 2 size = 3 size = 4 size = 2 size = 3 size = 3 size = 4 size = 5 size = 6 size = 7
Therefore, 11 is the answer.
The correct answer is: Polymorphism
Polymorphism is one of the four fundamental pillars of Object-Oriented Programming (OOP). The other three pillars are:
Encapsulation: Involves bundling data and methods that operate on the data into a single unit (class) and controlling access to the internal details of the object.
Inheritance: Allows a new class (subclass or derived class) to inherit attributes and methods from an existing class (superclass or base class), promoting code reuse.
Polymorphism: Enables objects of different types to be treated as objects of a common type. This can occur at compile time (compile-time polymorphism) through method overloading and operator overloading, and at runtime (run-time polymorphism) through method overriding.
So, while superclass and subclass are related to inheritance, and variable is a general term in programming, polymorphism is a specific pillar of Object-Oriented
Correct Answer: b. javac
BASIC (Beginner's All-purpose Symbolic Instruction Code) is a procedural programming language and does not support object-oriented programming concepts such as classes, objects, inheritance, and polymorphism.