Core Java Mock Test-3

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Leonfernando
L
Leonfernando
Community Contributor
Quizzes Created: 1 | Total Attempts: 683
| Attempts: 683 | Questions: 45
Please wait...
Question 1 / 45
0 %
0/100
Score 0/100
1. Consider the following scenario: Real Chocos Private Limited deals in manufacturing variety of chocolates. This organization manufactures three varieties of chocolates. 1. Fruit Chocolates 2. Rum Chocolates 3. Milk Chocolates A software system needs to be built. Which of the following options identifies the Classes and Objects?

Explanation

The correct answer is Class: Chocolate and Objects: Fruit Chocolates, Rum Chocolates, Milk Chocolates. This is because the question states that Real Chocos Private Limited manufactures three varieties of chocolates, namely Fruit Chocolates, Rum Chocolates, and Milk Chocolates. Therefore, the class would be Chocolate, which represents the general category of chocolates, and the objects would be the specific varieties of chocolates that the organization manufactures.

Submit
Please wait...
About This Quiz
Core Java Mock Test-3 - Quiz

INTRODUCTION TO OOPS
INTRODUCTION TO JAVA AND SDE
LANGUAGE FUNDAMENTALS AND OPERATORS

2. Consider the following code: class One { public One() { System.out.print(1); } } class Two extends One { public Two() { System.out.print(2); } } class Three extends Two { public Three() { System.out.print(3); } } public class Numbers { public static void main(String[] argv) { new Three(); } } Which of the following will be the output for the above program?

Explanation

The code defines three classes: One, Two, and Three. Each class has a constructor that prints a number. Class Three extends class Two, which extends class One. The main method creates an instance of class Three. When the instance is created, the constructors of all three classes are called in order. Therefore, the output will be 123.

Submit
3. Consider the following code: 1 public class A { 2 public void m1() {System.out.print("A.m1, ");} 3 protected void m2() {System.out.print("A.m2, ");} 4 private void m3() {System.out.print("A.m3, ");} 5 void m4() {System.out.print("A.m4, ");} 6 7 public static void main(String[] args) { 8 A a = new A(); 9 a.m1(); 10 a.m2(); 11 a.m3(); 12 a.m4(); 13 } 14 } Which of the following gives the lines that need to be removed in order to compile and run the above code correctly?

Explanation

The code will compile and run correctly without the need to comment any line. All the methods called in the main method (m1, m2, m3, m4) are accessible within the class A. The access modifiers (public, protected, private) do not affect the ability to call these methods within the same class. Therefore, no lines need to be removed for the code to compile and run correctly.

Submit
4. Consider the following code snippet:   String deepak = "Did Deepak see bees? Deepak did.";   Which of the following method calls would refer to the letter b in the string referred by the variable deepak?

Explanation

The method call charAt(15) refers to the letter "b" in the string "Did Deepak see bees? Deepak did.". The index of the character "b" in the string is 15, as indexing starts from 0. Therefore, calling the charAt(15) method will return the character "b".

Submit
5. Consider the following code: 1. class Test { 2. public static void main(String args[]) { 3. double d = 12.3; 4. Dec dec = new Dec(); 5. dec.dec(d); 6. System.out.println(d); 7. } 8. } 9. class Dec{ 10. public void dec(double d) { d = d - 2.0d; } 11. } Which of the following gives the correct value printed at line 6?

Explanation

In this code, a double variable "d" is initialized with the value 12.3. Then, an object of the class "Dec" is created and its method "dec" is called, passing the value of "d" as an argument. Inside the "dec" method, the argument "d" is subtracted by 2.0 and assigned back to "d". However, this does not affect the value of the original "d" variable outside the method. Therefore, when the value of "d" is printed at line 6, it still remains 12.3.

Submit
6. Consider the following code: class UT1 { static byte m1() { final char c = 'u0001'; return c; } static byte m3(final char c) { return c; } public static void main(String[] args) { char c = 'u0003'; System.out.print(""+m1()+m3(c)); } } Which of the following gives the valid output of the above code?

Explanation

The code will result in a compile-time error because the return type of the method m1() is declared as byte, but it is trying to return a char value. The char value 'u0001' cannot be implicitly converted to a byte, hence the code will not compile.

Submit
7. Consider the following code: class Alpha { protected Beta b; } class Gamma extends Alpha { } class Beta { } Which of the following statement is True?

Explanation

In the given code, class Gamma extends class Alpha, which means Gamma is a type of Alpha. Therefore, the statement "Gamma is-a Alpha" is true. Additionally, the code also declares a protected variable of type Beta in class Alpha, which means Gamma has a Beta. Therefore, the statement "Gamma has-a Beta" is also true.

Submit
8. Consider the following code: public class ExampleSeven { public static void main(String [] args) { String[] y = new String[1]; String x = "hello"; y[0] = x; // Code here System.out.println("match"); } else { System.out.println("no match"); } } } Which of the following code snippet when substituted at the commented line (// Code here) in the above code will make the program to print "no match"?

Explanation

The correct answer is "if (!x.equals(y[0])) {". This code snippet uses the "equals" method to compare the value of x and y[0]. The "!" operator negates the result of the comparison, so if x and y[0] are not equal, the condition will be true and "no match" will be printed.

Submit
9. Which of the following options gives the difference between == operator and equals() method?

Explanation

The correct answer is that the == operator compares the memory address of objects, while the equals() method compares the character sequence of objects.

Submit
10. Which of the following options gives the relationship between a Pilot class and Plane class?

Explanation

Association is a relationship between two classes where one class is connected to another class, but there is no ownership or dependency between them. In the given question, the relationship between a Pilot class and Plane class can be an association, as pilots can be associated with planes without any ownership or dependency.

Submit
11. Consider the following code: class A { } class B extends A { } public class Code2 { public void method(A a) { System.out.println("A"); } public void method(B b) { System.out.println("B"); } public static void main(String args[]) { new Code2().method(new Object()); } } Which of the following will be the output for the above code?

Explanation

The code will result in a compilation error because the method `method(A a)` in the `Code2` class does not have an overload that accepts an `Object` parameter. Therefore, the compiler cannot find the symbol `method(Object)`.

Submit
12. Consider the following code:  public class Code13 { public static void main(String... args)  { for(String s:args) System.out.print(s + ", "); System.out.println(args.length); } }  Which of the following will be the output if the above code is attempted to compile and execute?

Explanation

The code is written to accept command line arguments and print them as comma separated values. It then prints the length of the arguments-list. Since the code is using the enhanced for-loop to iterate over the arguments array, it will compile successfully and produce the expected output.

Submit
13. Consider the following code: public class Key1 { public boolean testAns( String ans, int n ) { boolean rslt; if (ans.equalsIgnoreCase("YES") & n > 5) rslt = true; return rslt; } public static void main(String args[]) { System.out.println(new Key1().testAns("no", 5)); } } Which of the following will be the output of the above program?

Explanation

The code will result in a compile-time error because the variable "rslt" is not initialized before it is returned in the method "testAns".

Submit
14. Consider the following code: public class ObParam{ public int b = 20; public static void main(String argv[]){ ObParam o = new ObParam(); methodA(o); } public static void methodA(ObParam a) { a.b++; System.out.println(a.b); methodB(a); System.out.println(a.b); } public void methodB(ObParam b) { b.b--; } } Which of the following gives the correct output for the above code?

Explanation

The correct answer is "Compilation Error: Non-static method methodB() cannot be referenced from static context methodA()". This is because the method methodB() is not declared as static, so it can only be accessed through an instance of the class. However, methodA() is a static method and does not have an instance of the class, so it cannot access the non-static method methodB(). This results in a compilation error.

Submit
15. Delimiters themselves be considered as tokens. State True or False.

Explanation

Delimiters themselves cannot be considered as tokens. Delimiters are characters used to separate or mark the boundaries of different tokens in a given text. Tokens, on the other hand, are meaningful units of information, such as words or symbols, that are extracted from the text. Delimiters serve as separators between tokens, but they are not considered tokens themselves. Therefore, the statement is false.

Submit
16. Consider the following code: public class LabeledBreak2 { public static void main(String args[]) { loop: for(int j=0; j<2; j++) { for(int i=0; i<10; i++) { if(i == 5) break loop; System.out.print(i + " "); } } } } Which of the following will be the output for the above code?

Explanation

The code contains a nested loop. The outer loop runs twice and the inner loop runs 10 times. Inside the inner loop, there is a condition that checks if the value of i is equal to 5. If it is, then the loop labeled "loop" is broken, causing the program to exit the inner loop and continue with the next iteration of the outer loop. Therefore, the output will be 0 1 2 3 4, as the inner loop is terminated before reaching the value 5.

Submit
17. Consider the following code snippet: class TestString2 { public static void main(String args[]) { String s1 = "Test1"; String s2 = "Test2"; s1.concat(s2); System.out.println(""+s1.charAt(s1.length() - 3) + s1.indexOf(s2)); } } What will be the output of the above code snippet?

Explanation

The code snippet creates two string objects, s1 and s2, with values "Test1" and "Test2" respectively. The concat() method is called on s1 and s2, but the result is not assigned to any variable. Therefore, the original values of s1 and s2 remain unchanged. The println() method is then called, concatenating the character at index (length - 3) of s1 with the index of s2 in s1. Since s1.concat(s2) does not modify s1, the index of s2 in s1 is -1. Therefore, the output will be "s-1".

Submit
18. Consider the following code: public class TestOne { public static void main(String args[]) { byte x = 3; byte y = 5; System.out.print((y%x) + ", "); System.out.println(y == ((y/x) *x +(y%x))); } } Which of the following gives the valid output for above?

Explanation

The code first calculates the remainder of y divided by x using the modulus operator (%), which is 5 % 3 = 2. It then prints this value, followed by a comma.

Next, it checks if y is equal to the result of ((y/x) * x + (y%x)). Since y is 5, and ((y/x) * x + (y%x)) simplifies to ((5/3) * 3 + (5%3)) = (1 * 3 + 2) = 5, the condition y == ((y/x) * x + (y%x)) evaluates to true.

Therefore, the code prints "2, true".

Submit
19. Consider the following code: class Planet { } class Earth extends Planet { } public class WelcomePlanet { public static void welcomePlanet(Planet planet)  { if (planet instanceof Earth) { System.out.println("Welcome!"); }  else if (planet instanceof Planet)  { System.out.println("Planet!"); } else { System.exit(0); } } public static void main(String args[])  { WelcomePlanet wp = new WelcomePlanet(); Planet planet = new Earth(); welcomePlanet(planet); } } Which of the following will be the output of the above program?

Explanation

The output of the above program will be "Welcome!" because the object "planet" is an instance of the subclass Earth, which means it is also an instance of the superclass Planet. Therefore, the condition "planet instanceof Earth" will evaluate to true and the corresponding message "Welcome!" will be printed.

Submit
20. Consider the following code snippet: public class Welcome { String title; int value; public Welcome() { title += " Planet"; } public void Welcome() { System.out.println(title + " " + value); } public Welcome(int value) { this.value = value; title = "Welcome"; Welcome(); } public static void main(String args[]) { Welcome t = new Welcome(5); } } Which of the following option will be the output for the above code snippet?

Explanation

The code will output "Welcome 5". This is because the constructor with the int parameter is called when creating a new instance of the Welcome class. Inside this constructor, the value variable is assigned the value 5 and the title variable is assigned the value "Welcome". Then, the Welcome() method is called, which prints out the value of the title and value variables. Since the title variable was previously assigned the value "Welcome" in the constructor, the output will be "Welcome 5".

Submit
21. Consider the following program: public class D extends Thread { public void run() { System.out.println("Before start method"); this.stop(); System.out.println("After stop method"); } public static void main(String[] args) { D a = new D(); a.start(); } } What will be the output of the above program?

Explanation

The program will output 'Before start method' only. This is because the stop() method is called immediately after the start() method, which causes the thread to stop before it has a chance to execute the rest of the code in the run() method. Therefore, the "After stop method" print statement is never reached.

Submit
22. Consider the following partial code: public class CreditCard { private String cardID; private Integer limit; public String ownerName; public void setCardInformation(String cardID, String ownerName, Integer limit) { this.cardID = cardID; this.ownerName = ownerName; this.limit = limit; } } Which of the following statement is True regarding the above given code?

Explanation

The ownerName variable breaks encapsulation because it is declared as public, which means it can be accessed and modified directly from outside the class. Encapsulation is a principle of object-oriented programming that aims to hide the internal details of an object and only expose necessary information through methods. By declaring ownerName as public, it violates this principle and allows external code to directly manipulate the variable.

Submit
23. Consider the following code: 1. public class DagRag { 2. public static void main(String [] args) { 3. 4. int [][] x = new int[2][4]; 5. 6. for(int y = 0; y < 2; y++) { 7. for(int z = 0; z < 4; z++) { 8. x[y][z] = z; 9. } 10. } 11. 12. dg: for(int g = 0; g < 2; g++) { 13. rg: for(int h = 0; h < 4; h++) { 14. System.out.println(x[g][h]); 15. 16. } 17. System.out.println("The end."); 18. 19. } 20. 21. } 22. } Which of the following code snippet when inserted at lines 15 and 18 respectively, will make the above program to generate the below output? 0 1 2 3 The end.

Explanation

The code snippet "if(h==3) break rg; if(g==0) break dg;" will make the program generate the given output because it breaks out of the inner loop when h is equal to 3 and breaks out of the outer loop when g is equal to 0. This ensures that the inner loop iterates until h reaches 3 and the outer loop iterates until g reaches 0, allowing all the elements of the array to be printed before "The end." is printed.

Submit
24. Consider the following code snippet: class Animal { String name; public boolean equals(Object o) { Animal a = (Animal) o; // Code Here } } class TestAnimal { public static void main(String args[]) { Animal a = new Animal(); a.name = "Dog"; Animal b = new Animal(); b.name = "dog"; System.out.println(a.equals(b)); } } Which of the following code snippets should be replaced for the comment line (//Code Here) in the above given code, to get the output as true?

Explanation

The correct answer is "return this.name.equalsIgnoreCase(a.name);" because it compares the names of the two Animal objects, ignoring the case sensitivity. This will return true if the names are equal, regardless of whether they are in uppercase or lowercase.

Submit
25. Consider the following code snippet: public class TestString9 { public static void main(String st[]){ String s1 = "java"; String s2 = "java"; String s3 = "JAVA"; s2.toUpperCase(); s3.toUpperCase(); boolean b1 = s1==s2; boolean b2 = s1==s3; System.out.print(b1); System.out.print(" "+b2); } } What will be the output of the above code snippet?

Explanation

The output of the code snippet will be "true false". This is because the string objects s1 and s2 both have the same value "java", so when comparing them using the "==" operator, it will return true. However, the string object s3 has a different value "JAVA" which is in uppercase. When calling the toUpperCase() method on s3, it does not change the original string object, so s3 still remains "JAVA". Therefore, when comparing s1 and s3 using the "==" operator, it will return false.

Submit
26. Consider the following code: 1. public class SwitchIt { 2. public static void main(String[] args) 3. int w1 = 1; 4. int w2 = 2; 5. System.out.println(getW1W2(w1, w2)); 6. } 7. 8. public static int getW1W2(int x, int y) { 9. switch (x) { 10. case 1: x = x + y; 11. case 2: x = x + y; 12. } 13. return x; 14. } 15. } Which of the following gives the valid output of above code?

Explanation

The code will compile successfully because there are no syntax errors. The program will print "5" as the output because the value of x is initially set to 1 and the switch statement will execute the case 1 and case 2 statements, adding the value of y to x twice. Therefore, x will be equal to 5 when it is returned.

Submit
27. Which of the following flow control features does Java support? (Choose 2)

Explanation

Java supports the flow control features of labeled continue and labeled break. Labeled continue is used to skip the current iteration of a loop and move to the next iteration, while labeled break is used to exit a loop or switch statement. Labeled goto, labeled throw, and labeled catch are not supported by Java.

Submit
28. Which of the following options gives the relationship between a Spreadsheet Object and Cell Objects?

Explanation

Aggregation is the correct answer because it represents a relationship between objects where one object is composed of or contains other objects. In the context of a spreadsheet, a Spreadsheet Object can be composed of or contain multiple Cell Objects. This relationship allows for the organization and manipulation of data within the spreadsheet.

Submit
29. Which of the following codes will compile and run properly?

Explanation

The correct answer is public class Test2 { static public void main(String[] in) { System.out.println("Test2"); } } because it follows the correct syntax for the main method in Java. The main method must be declared as public, static, and void, and it must accept an array of strings as a parameter. Additionally, the class name must match the file name, and the code inside the main method will be executed when the program is run.

Submit
30. Consider the following code: public class Code4 { private int second = first; private int first = 1000; public static void main(String args[]) { System.out.println(new Code4().second); } } Which of the following will be the output for the above code?

Explanation

The code is trying to assign the value of the variable "first" to the variable "second" before "first" is actually declared. This is known as forward referencing, and it is not allowed in Java. Therefore, the compiler will complain about this error.

Submit
31. Consider the following code: class ExampleFive { public static void main(String[] args) { final int i = 22; byte b = i; System.out.println(i + ", " + b); } } Which of the following gives the valid output for the above code?

Explanation

The code initializes a final int variable i with a value of 22. It then tries to assign the value of i to a byte variable b. Since byte is a smaller data type than int, there is a potential loss of precision. However, in this case, the value of i (22) can be safely represented as a byte, so no compilation error occurs. Therefore, the code will print "22, 22" as the output.

Submit
32. Which of the following are true about inheritance?(Choose 3)

Explanation

Inheritance allows a subclass to inherit the properties and methods of its superclass, which means that a subclass can also act as a superclass in an inheritance hierarchy. This allows for code reuse and promotes modularity. Additionally, inheritance enables adding new features and functionality to an existing class without modifying the existing class, which helps to maintain the integrity of the original class and simplifies the process of extending its capabilities.

Submit
33. Which of the following statements are correct regarding Static Blocks?(Choose 3)

Explanation

A class can have more than one static block: This statement is correct because a class can have multiple static blocks, which are used to initialize static variables or perform other tasks before the class is used.

Static blocks are executed only once: This statement is correct because static blocks are executed only once when the class is loaded into memory. They are not executed again even if the class is instantiated multiple times.

Static blocks are executed before the main() method: This statement is correct because static blocks are executed in the order they appear in the code, before the main() method is executed. This allows any necessary initialization to be performed before the main() method starts executing.

Therefore, the correct statements regarding static blocks are that a class can have more than one static block, static blocks are executed only once, and static blocks are executed before the main() method.

Submit
34. Which are all platform independent among the following? (Choose 3)

Explanation

JAR Files, Java Class Files, and Java Source Files are all platform independent. JAR files are archives that contain compiled Java classes and resources, which can be executed on any platform that supports Java. Java Class Files are the compiled bytecode version of Java source code, which can also be executed on any platform with a Java Virtual Machine (JVM). Java Source Files are the human-readable version of Java code, which can be compiled into Java Class Files and executed on any platform with a JVM. The JVM is not platform independent itself, but it allows Java code to run on different platforms.

Submit
35. Consider the following code: public class SwitchIt { public static void main(String args[]) { int x = 10; switch(x) { case 10: for(int i=0; i break; case 20: System.out.println(x); break; case 30: System.out.println(x*2); break; default: System.out.println(x*3); } } } Which of the following will be the output for the above program?

Explanation

The output for the above program will be 10. This is because the value of x is 10, which matches the case 10 in the switch statement. Therefore, the code inside the case 10 block will be executed, which includes the statement System.out.println(x). This will print the value of x, which is 10, as the output.

Submit
36. Which of the following classes is new to JDK 1.6?

Explanation

The class "java.io.Console" is new to JDK 1.6. This class provides a way to interact with the user through the command line, allowing input and output operations. It was introduced in JDK 1.6 to enhance the capabilities of command line applications in Java.

Submit
37. Which of the following methods are defined in Object class? (Choose 3)

Explanation

The methods toString(), hashCode(), and equals(Object) are defined in the Object class. The toString() method returns a string representation of an object, the hashCode() method returns the hash code value for an object, and the equals(Object) method checks if two objects are equal. These methods are inherited by all classes in Java as the Object class is the root class for all classes in Java. The run() and compareTo(Object) methods are not defined in the Object class.

Submit
38. Consider the following code snippet: class Train { String name = "Shatapdhi"; } class TestTrain { public static void main(String a[]) { Train t = new Train(); System.out.println(t); // Line a System.out.println(t.toString()); // Line b } } Which of the following statements are true?(Choose 3)

Explanation

Line a prints the corresponding classname with Object's hashcode in Hexadecimal because when we print an object without explicitly calling the toString() method, it automatically calls the toString() method of the Object class. The default implementation of toString() in the Object class returns the classname followed by the hashcode of the object in hexadecimal format. Therefore, Line a prints the classname "Train" along with the hashcode of the object in hexadecimal.

Both Line a and Line b will print the corresponding classname with Object's hashcode in Hexa Decimal because the toString() method is explicitly called in Line b. The toString() method in the Train class is not overridden, so it calls the toString() method of the Object class, which returns the classname followed by the hashcode of the object in hexadecimal format.

The output of Line a and Line b will be the same because both statements print the classname followed by the hashcode of the object. Since the object is the same in both cases, the hashcode will be the same, resulting in the same output.

Submit
39. Consider the following code: 1. public class Circle1 { 2. private String string = "String1"; 3. void work() { 4. String x = "String2"; 5. class Circle2 { 6. public void peepOut() { 7. System.out.println(string); 8. System.out.println(x); 9. } 10. } 11. new Circle2().peepOut(); 12. } 13. 14. public static void main(String args[]) { 15. Circle1 c1 = new Circle1(); 16. c1.work(); 17. } 18. } Which of the following changes made to the above code will make the code to compile and execute properly and gives the following output? String1 String2

Explanation

The variable at line 4 should be declared as final because it is being accessed by the inner class Circle2. In order for the inner class to access the variable, it needs to be declared as final to ensure that its value does not change.

Submit
40. Consider the following code: class Animal { public String noise() { return "noise"; } } class Dog extends Animal { public String noise() { return "bark"; } } class Cat extends Animal { public String noise() { return "meow"; } } class MakeNoise { public static void main(String args[]) { Animal animal = new Dog(); Cat cat = (Cat)animal; System.out.println(cat.noise()); } } Which of the following option will be the output of the above code snippet?

Explanation

The code snippet tries to cast an instance of the Dog class to the Cat class. However, since a Dog is not a subclass of Cat, a ClassCastException will be thrown at runtime.

Submit
41. Consider the following code: public class Choco { Choco() { System.out.print("Choco"); } class Bar { Bar() { System.out.print("bar"); } public void go() { System.out.print("sweet"); } } public static void main(String[] args) { Choco c = new Choco(); c.makeBar(); } void makeBar(){ // Insert code here } } Which of the following code snippet when substituted individually to the above commented line (// Insert code here) will give the following output?

Explanation

The correct answer is "(new Bar() {}).go();". This code creates a new instance of the Bar class using an anonymous inner class and then calls the go() method on that instance. The output will be "barsweet".

Submit
42. Which of the following statements are true? (Choose 2)

Explanation

The first statement, "All exceptions are thrown programmatically from the code or API," is false. Exceptions can be thrown programmatically, but they can also be thrown automatically by the JVM or other system components.

The second statement, "All exceptions are thrown by JVM," is false. While the JVM does throw some exceptions, not all exceptions are thrown by the JVM. Exceptions can also be thrown programmatically by the code or API.

The third statement, "JVM cannot throw user-defined exceptions," is true. User-defined exceptions are exceptions that are created by the programmer, and the JVM does not throw these types of exceptions.

The fourth statement, "JVM thrown exceptions can be thrown programmatically," is true. The JVM can throw exceptions, and these exceptions can also be thrown programmatically by the code or API.

The fifth statement, "All RuntimeException are thrown by JVM," is false. While the JVM does throw some RuntimeExceptions, not all RuntimeExceptions are thrown by the JVM. RuntimeExceptions can also be thrown programmatically by the code or API.

Submit
43. Consider the following code: public class GetArray { public static void main(String args[]) { float invt[][]; float[] prct, grts[]; float[][] sms, hms[]; (// Insert statement1 here) (// Insert statement2 here) (// Insert statement3 here) } } Which of the following listed statements can be inserted at the above commented lines (// Insert statement1 here, // Insert statement2 here, // Insert statement3 here) to make the program to compile without errors? (Choose 3)

Explanation

The first statement "grts = new float[1][4];" creates a 2-dimensional float array with 1 row and 4 columns and assigns it to the variable "grts". This statement is valid and does not cause any compilation errors.

The second statement "invt = grts;" assigns the value of "grts" to the variable "invt". Since both variables are of the same type (2-dimensional float array), this assignment is valid and does not cause any compilation errors.

The third statement "invt = new float[4][2];" creates a new 2-dimensional float array with 4 rows and 2 columns and assigns it to the variable "invt". This statement is also valid and does not cause any compilation errors.

Therefore, the three listed statements can be inserted at the commented lines to make the program compile without errors.

Submit
44. Which of the following statements are correct regarding Instance Block?(Choose 3)

Explanation

A class can have more than one instance block: This statement is correct because a class can have multiple instance blocks, which are used to initialize instance variables or perform other actions before the object is created.

Instance blocks are executed before constructors: This statement is correct because instance blocks are executed before constructors during the object creation process. Instance blocks are used to initialize instance variables, and they are executed before any constructor code is executed.

Instance blocks are executed for every created instance: This statement is correct because instance blocks are executed every time a new instance of the class is created. This ensures that the necessary initialization or actions are performed for each individual instance.

Submit
45. Consider the following code: 1. public class Garment { 2. public enum Color { 3. RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff); 4. private final int rgb; 5. Color( int rgb) { this.rgb = rgb; } 6. public int getRGB() { return rgb; } 7. }; 8. public static void main( String[] argv) { 9. // insert code here 10. } 11.} Which of the following code snippets, when inserted independently at line 9, allow the Garment class to compile? (Choose 2)

Explanation

The code snippet "Color treeColor = Color.GREEN;" allows the Garment class to compile because it creates a new variable "treeColor" of type Color and assigns it the value of Color.GREEN, which is one of the enum constants defined in the Color enum.

The code snippet "if( Color.RED.ordinal()

Submit
View My Results

Quiz Review Timeline (Updated): Sep 5, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Sep 05, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Dec 14, 2011
    Quiz Created by
    Leonfernando
Cancel
  • All
    All (45)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Consider the following scenario:...
Consider the following code:...
Consider the following code:...
Consider the following code snippet:...
Consider the following code:...
Consider the following code:...
Consider the following code:...
Consider the following code:...
Which of the following options gives the difference between ==...
Which of the following options gives the relationship between a Pilot...
Consider the following code:...
Consider the following code:...
Consider the following code:...
Consider the following code:...
Delimiters themselves be considered as tokens. State True or False.
Consider the following code:...
Consider the following code snippet:...
Consider the following code:...
Consider the following code:...
Consider the following code snippet:...
Consider the following program:...
Consider the following partial code:...
Consider the following code:...
Consider the following code snippet:...
Consider the following code snippet:...
Consider the following code:...
Which of the following flow control features does Java support?...
Which of the following options gives the relationship between a...
Which of the following codes will compile and run properly?
Consider the following code:...
Consider the following code:...
Which of the following are true about inheritance?(Choose 3)
Which of the following statements are correct regarding Static...
Which are all platform independent among the following? (Choose 3)
Consider the following code:...
Which of the following classes is new to JDK 1.6?
Which of the following methods are defined in Object class? (Choose 3)
Consider the following code snippet:...
Consider the following code:...
Consider the following code:...
Consider the following code: public class Choco { Choco() {...
Which of the following statements are true? (Choose 2)
Consider the following code:...
Which of the following statements are correct regarding Instance...
Consider the following code:...
Alert!

Advertisement