1.
Choose the best definition for a Class.
Correct Answer
B. An object definition, containing the data and function elements necessary to create an object
Explanation
A class is an object definition that contains the necessary data and function elements required to create an object. In object-oriented programming, a class serves as a blueprint or template for creating objects. It defines the properties (data) and behaviors (functions) that an object of that class can have. By creating multiple objects from a class, we can utilize the defined properties and behaviors to perform specific actions or tasks.
2.
Choose the best definition of an object
Correct Answer
B. An instance of a class
Explanation
An object is best defined as an instance of a class. In object-oriented programming, a class is a blueprint or template that defines the properties and behaviors of objects. An object, on the other hand, is a specific instance created from that class, with its own unique set of values for the class's properties. Therefore, an object is not just any thing or something you wear, but specifically an instance of a class.
3.
Choose the appropriate data type for this value: "dog"
Correct Answer
B. String
Explanation
The value "dog" is a word or a sequence of characters, which is represented by the data type String. The String data type is used to store textual data in programming languages and is the appropriate choice for representing words, sentences, or any other combination of characters.
4.
Choose the appropriate data type for this value: true
Correct Answer
D. Boolean
Explanation
The correct answer is boolean because the value "true" is a boolean value, representing either true or false. The boolean data type is used to store and manipulate boolean values in programming languages.
5.
Choose the appropriate data type for this value: 1
Correct Answer
A. Int
Explanation
The value 1 is a whole number and does not contain any decimal places. Therefore, the appropriate data type for this value is "int," which represents integers or whole numbers in programming.
6.
Choose the appropriate data type for this value: 5.5
Correct Answer
B. Double
Explanation
The value 5.5 is a decimal number, so the appropriate data type to represent it would be double. The double data type is used to store floating-point numbers with a higher precision than the float data type.
7.
Choose the appropriate data type for this value: A
Correct Answer
C. Char
Explanation
The appropriate data type for the value "A" would be char. The value "A" is a single character, so it can be stored as a char data type.
8.
Choose the appropriate data type for this value: "x1"
Correct Answer
A. String
Explanation
String's always have " " around them!
9.
Choose the appropriate data type for this value: true
Correct Answer
A. Boolean
Explanation
true/false = boolean (only two possible answers)
10.
Choose the appropriate data type for this field: kindOfBird
Correct Answer
A. String
Explanation
example: kindOfBird = "Parrot"
11.
Choose the appropriate data type for this field: numberOfEggs
Correct Answer
D. Int
Explanation
The appropriate data type for the field "numberOfEggs" is int because it suggests that the field will store a whole number value representing the count of eggs. The int data type is used for storing integers, which are whole numbers without any decimal places.
12.
Choose the appropriate data type for this field: weightInKilos
Correct Answer
C. Double
Explanation
The appropriate data type for the field "weightInKilos" would be double. This is because weight is typically represented as a decimal number and the double data type can accommodate decimal values with a larger range than the float data type. Using a double data type allows for more precise calculations and storage of weight values in kilograms.
13.
Choose the appropriate data type for this field: isSwimmer
Correct Answer
B. Boolean
Explanation
isSwimmer - yes or no (only two possible answers = boolean)
14.
Choose the appropriate data type for this field: eggColour
Correct Answer
D. String
Explanation
The field "eggColour" suggests that it is referring to the color of an egg. Since egg colors can vary and are not limited to a specific set of options, a String data type would be appropriate. String data type allows for storing a sequence of characters, which can accommodate different egg colors as text.
15.
System.out.print (2+5)
What is the possible out for this?
Correct Answer
A. 7
Explanation
The statement "System.out.print(2+5)" is a Java code that prints the result of the expression "2+5" to the console. Since the expression evaluates to 7, the output will be 7.
16.
Int a=5, b=10, sum;
sum=a+b
System.out.print("The sum of two integers is:" ____)
What is the correct java syntax for this:
Correct Answer
B. +sum
Explanation
The correct Java syntax for printing the sum of two integers is "+sum". This is because the variable "sum" holds the value of the addition operation between variables "a" and "b", and the "+" symbol is used to concatenate the string "The sum of two integers is:" with the value of "sum" when printing it.
17.
An old name for Java Programming
Correct Answer
D. Oak
Explanation
Oak was the original name for the programming language that eventually became Java. It was developed by James Gosling and his team at Sun Microsystems in the early 1990s. However, due to trademark issues, the name was changed to Java. Oak was designed to be a platform-independent language for programming consumer electronics devices, but it was later adapted and rebranded as Java for broader use in web and application development.
18.
Which of the following always need a Capital letter ?
Correct Answer
A. Class names and Strings
Explanation
Class names and Strings always need a capital letter because it is a common convention in programming languages to use capital letters to distinguish between different types of identifiers. Class names typically start with a capital letter to make them easily recognizable and distinguishable from variables and methods. Similarly, Strings are often written with a capital letter at the beginning to indicate that they are a specific type of data.
19.
A data types that holds decimal numbers:
Correct Answer
A. Double
Explanation
The data type "double" is used to hold decimal numbers in programming. It allows for the storage of both whole numbers and numbers with decimal points. This data type is commonly used in situations where precision is required, such as in financial calculations or scientific computations. Unlike integer data types, which can only store whole numbers, the double data type can represent a wider range of values, including fractions and very large or very small numbers. Therefore, "double" is the correct answer for a data type that holds decimal numbers.
20.
Your program file name is the same with___?
Correct Answer
B. Class Name
Explanation
The correct answer is "Class Name" because in Java, the program file name must match the name of the class that contains the main method. This is a requirement for the Java compiler to be able to identify and execute the program correctly. Therefore, the program file name should be the same as the class name to ensure proper execution.
21.
Public class Test {
static void main(String[] args)
{
System.out.println("Hello World"); } }
What must be the file name of this java program?
Correct Answer
B. Test.java
Explanation
The file name of a Java program must match the name of the public class in the program. In this case, the public class is named "Test", so the file name must be "Test.java".
22.
Public class Test {
static void main(String[] args)
{
System.out.println("Hello World"); }
Is there any syntax error for this program?
Correct Answer
A. Yes, there is a Syntax error
Explanation
The given program has a syntax error because the main method should be declared as public in order to be accessed by the Java Virtual Machine (JVM). Additionally, the closing parenthesis after "args" is missing, which is also a syntax error.
23.
Public class Test{
static void main(String[] args)
{
System.out.println("Hello World"); }}
What is the correct syntax in compiling java program?
Correct Answer
C. Javac Test.java
Explanation
The correct syntax for compiling a Java program is "javac Test.java". This command is used to compile the Java source code file named "Test.java" into bytecode, which can then be executed by the Java Virtual Machine.
24.
Public class Test{
static void main(String[] args)
{
System.out.println("Hello World"); }}
What is the correct syntax in compiling java program?
Correct Answer
C. Javac Test.java
Explanation
The correct syntax for compiling a Java program is "javac Test.java". This command is used to compile the Java source code file named "Test.java" into bytecode, which can then be executed by the Java Virtual Machine.
25.
What is the error in this following java program:
public class Employee {
public showName () {
name = Walter;
System.out.println ("Employee's name is: " + name);
}
}
Correct Answer
A. No data type declared
Explanation
The error in this Java program is that no data type is declared for the method "showName()". In Java, every method should have a return type specified, even if it is void. Therefore, the correct way to declare the method would be "public void showName()".
26.
public class Example2
{
public static void main ( String[] args )
{int hoursWorked = 40;
double payRate = 10.0;
System.out.println("Hours Worked: " + hoursWorked );
System.out.println("pay Amount : "+ (hoursWorked*payRate));
}
}
What is the possible output of this program?
Correct Answer
B. Hours Worked:40
pay Amount :400
Explanation
The possible output of this program is "Hours Worked: 40" and "pay Amount : 400". This is because the program initializes the variable "hoursWorked" with a value of 40 and the variable "payRate" with a value of 10.0. It then calculates the pay amount by multiplying the hours worked by the pay rate and prints it out using the System.out.println() method. In this case, the calculation would be 40 * 10.0 = 400, resulting in the output "pay Amount : 400".
27.
Import java.util.Scanner;
public class MyClass {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
int num = input.nextInt();
if(num % 2 == 0)
System.out.print(num+" is an even number");
else
System.out.print(num+" is an odd number");
}
}
What would the the Possible output if the given integer is 12?
Correct Answer
A. 12 is an even number
Explanation
The possible output if the given integer is 12 would be "12 is an even number". This is because the code checks if the given number is divisible by 2 using the modulus operator (%). If the remainder is 0, it means the number is even, so the program prints "is an even number" along with the given number. In this case, since 12 is divisible by 2 without any remainder, the output would indicate that it is an even number.
28.
Import java.util.Scanner;
public class MyClass {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
int num = input.nextInt();
if(num % 2 == 0)
System.out.print(num+" is an even number");
else
System.out.print(num+" is an odd number");
}
}
What syntax determine the number to be inputted by the user?
Correct Answer
C. Int num = input.nextInt();
Explanation
The syntax "int num = input.nextInt();" determines the number to be inputted by the user. It uses the Scanner class to create an object called "input" that reads input from the user. The "nextInt()" method is then used to read the next integer entered by the user and assign it to the variable "num". This allows the program to use the user's input for further calculations or processing.
29.
Import java.util.Scanner;
public class MyClass {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
int num = input.nextInt();
if(num % 2 == 0)
System.out.print(num+" is an even number");
else
System.out.print(num+" is an odd number");
}
}
What syntax determine the conditional statement?
Correct Answer
D. If(num % 2 == 0)
Explanation
The syntax that determines the conditional statement is "if(num % 2 == 0)". This statement checks if the remainder of the division of the variable "num" by 2 is equal to 0. If it is, then the number is even.
30.
Import java.util.Scanner;
public class MyClass {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
int num = input.nextInt();
if(num % 2 == 0)
System.out.print(num+" is an even number");
else
System.out.print(num+" is an odd number");
}
}
What syntax that display the integer inputted by the user?
Correct Answer
B. System.out.print("Enter an integer: ");
Explanation
The syntax "System.out.print("Enter an integer: ");" is used to display the prompt message asking the user to enter an integer.
31.
Import java.util.Scanner;
public class MyClass {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
int num = input.nextInt();
if(num % 2 == 0)
System.out.print(num+" is an even number");
else
System.out.print(num+" is an odd number");
}
}
What data types declared in this program?
Correct Answer
B. Integer
Explanation
The data type declared in this program is integer. This is because the variable "num" is declared as an int and is used to store the user input, which is expected to be an integer.
32.
What is .java
Correct Answer
C. An extension file
Explanation
The correct answer is "An extension file." In Java programming, the .java extension is used to identify source code files written in the Java programming language. These files contain the code that is written by developers and are later compiled into executable files with the .class extension. The .java extension is not an executable file itself, but rather indicates that the file contains Java source code.
33.
What is the output of this program?
-
class increment {
-
public static void main(String args[])
-
{
-
int g = 3;
-
System.out.print(++g * 8);
-
}
-
}
Correct Answer
C. 32
Explanation
The program declares a variable "g" and assigns it the value 3. The expression "++g" increments the value of "g" by 1 before the multiplication. So, "++g * 8" is equivalent to "4 * 8", which results in 32.
34.
-
class area {
-
public static void main(String args[])
-
{
-
double r, pi, a;
-
r = 9.8;
-
pi = 3.14;
-
a = pi * r * r;
-
System.out.println(a);
-
}
-
}
Correct Answer
A. 301.5656
Explanation
The given code calculates the area of a circle using the formula A = πr^2. The variables r and pi are initialized with values 9.8 and 3.14 respectively. The area is then calculated by multiplying pi, r, and r together. The result is printed to the console, which in this case is 301.5656.
35.
-
class mainclass {
-
public static void main(String args[])
-
{
-
boolean var1 = true;
-
boolean var2 = false;
-
if (var1)
-
System.out.println(var1);
-
else
-
System.out.println(var2);
-
}
-
}
Correct Answer
C. True
Explanation
The code declares two boolean variables, var1 and var2, with values true and false respectively. The if statement checks if var1 is true, and since it is, it prints out the value of var1, which is true. Therefore, the correct answer is true.
36.
-
class dynamic_initialization
-
{
-
public static void main(String args[])
-
{
-
double a, b;
-
a = 3.0;
-
b = 4.0;
-
double c = Math.sqrt(a * a + b * b);
-
System.out.println(c);
-
}
-
}
Correct Answer
B. 5.0
Explanation
The program calculates the value of c using the Pythagorean theorem, which states that in a right triangle, the square of the length of the hypotenuse (c) is equal to the sum of the squares of the other two sides (a and b). In this case, a is 3.0 and b is 4.0. The program then uses the Math.sqrt() function to find the square root of the sum of a^2 and b^2, which is 5.0. Therefore, the correct answer is 5.0.
37.
-
class dynamic_initialization
-
{
-
public static void main(String args[])
-
{
-
double a, b;
-
a = 3.0;
-
b = 4.0;
-
double c = Math.sqrt(a * a + b * b);
-
System.out.println(c);
-
}
-
}
Correct Answer
B. 5.0
Explanation
The code initializes two variables, "a" and "b", with the values 3.0 and 4.0 respectively. It then calculates the value of "c" using the formula Math.sqrt(a * a + b * b), which computes the square root of the sum of the squares of "a" and "b". In this case, the value of "c" is 5.0. Finally, the code prints the value of "c" to the console.
38.
Write the following Java Program that will display this output:
Look for the class name on the image display:
Look for the output that will display on your program:
Correct Answer
class KNHS {
public static void main(String[] args)
{
System.out.println("I am a Student of Kalayaan National High School");
}
}
Explanation
The given answer is correct because it includes the correct class name "KNHS" and the correct main method signature "public static void main(String[] args)". It also includes the correct statement to display the output "System.out.println("I am a Student of Kalayaan National High School");". Therefore, when this program is executed, it will display the desired output.