1.
What is the file extension of a java source program ?
Correct Answer
C. Java
Explanation
The file extension of a Java source program is "java". This is because Java source code files are typically saved with a .java extension. This allows the Java compiler and other tools to recognize and process the file as a Java source code file.
2.
You can recognise a constructor of a class because:
Correct Answer
A. It has the same name as the class and no return type
Explanation
A constructor is a special method in a class that is used to initialize objects of that class. It has the same name as the class and no return type because its purpose is to create and initialize an instance of the class, rather than returning a value. This allows the constructor to be called automatically when an object is created, using the new keyword.
3.
The primary function of a constructor is to
Correct Answer
C. Make a memory copy of a class and return a pointer to that instance
Explanation
The given answer is incorrect. The primary function of a constructor is to initialize the object of a class. It is responsible for setting the initial state of the object and allocating memory for it. Constructors do not make a memory copy of a class and return a pointer to that instance.
4.
The place where classes are stored and manipulated is called a
Correct Answer
D. Heap
Explanation
A heap is a data structure that stores and organizes data in a specific way. In computer programming, a heap is a region of memory used for dynamic memory allocation. It is a region of memory where objects are stored and manipulated. Unlike a stack, which is a specific type of data structure that follows the Last In First Out (LIFO) principle, a heap does not have a specific order for accessing or removing elements. Instead, it allows for efficient allocation and deallocation of memory at runtime. Therefore, the correct answer is heap.
5.
A constructor is called with the keyword
Correct Answer
A. new
Explanation
The correct answer is "new". In object-oriented programming, the "new" keyword is used to create an instance of a class and call its constructor. The constructor is a special method that is automatically invoked when an object is created. It initializes the object's state and performs any necessary setup. Therefore, when we want to create a new object, we use the "new" keyword to call its constructor.
6.
How many constructors can a class have ?
Correct Answer
B. As many as required
Explanation
A class can have as many constructors as required. Constructors are special methods used to initialize objects of a class. Different constructors can be created with different parameters to allow for various ways of initializing objects. Therefore, the number of constructors a class can have depends on the specific requirements and needs of the program or application being developed.
7.
Whta is the access scope of a variable declared inside a method block
Correct Answer
B. Only from within that method
Explanation
The access scope of a variable declared inside a method block is limited to only within that method. This means that the variable cannot be accessed or used outside of the method block. It is local to the method and can only be used within the method's code block. Other methods or classes within the same file or different files cannot access this variable.
8.
What is the first line of the first method executed in a java application:
Correct Answer
B. Public static void main ( String args) {
Explanation
The correct answer is "public static void main ( String args) {". This is the correct first line of the first method executed in a Java application because the main method is the entry point of a Java program and it must be declared with the "public" and "static" keywords. The method name is "main" and it takes a String array as its argument named "args".
9.
Java swing windows applications generally extend JFrame because
Correct Answer
D. The language developers have already prepared JFrame with many useful methods
Explanation
Java swing windows applications generally extend JFrame because the language developers have already prepared JFrame with many useful methods. This allows developers to easily add functionality and customize the window application according to their needs. JFrame provides methods for managing the window, handling events, and adding components to the user interface. By extending JFrame, developers can take advantage of these pre-existing methods and save time and effort in implementing common window functionalities.
10.
How many bits does an int primitive variable have ?
Correct Answer
B. 32
Explanation
An int primitive variable in most programming languages, including Java, has a size of 32 bits. This means it can store values ranging from -2,147,483,648 to 2,147,483,647. The size of an int variable is fixed and does not change regardless of the platform or system it is being used on.