The course is part of this learning path
In this course, we will learn the concepts of Java EE 7 with a focus on Java Basics.
- What Java classes, Executable Java, Access Modifiers are and how they work
- Anyone looking to get Oracle Java Certification
- Those who want to improve Java 7 EE knowledge
- Java developers
- Have at least 2 years of Java development experience
Hello there. In this video, we will examine our questions' answers. So, let's start. What are the valid components of a Java source file?
Answer; A, B, C, D. Explanation: The Java compiler and Java Runtime Environment aren't components of a Java source file. The following numbered list of Java class components is not in any particular order. Select the correct order of their occurrence in a Java class, choose all that apply? Answer; A, B, D. Explanation: The comments can appear anywhere in a class. They can appear before and after package and import statements. They can appear before or after a class, method, or variable declaration. The first statement, if present in a class, should be a package statement. It can't be placed after an import statement or a declaration of a class. The import statement should follow a package statement, and be followed by a class declaration.
The class declaration follows the import statements if present. It's followed by the declaration of the methods and variables. Answer C is incorrect. None of the variables or methods can be defined before the definition of a class or interface. Which of the following examples define the correct Java class structure? Answer, D. Explanation: Answer A is incorrect because #connect isn't a statement in Java. '#' is used to add comments in Unix. Option, B is incorrect because a package name, Java compiler, cannot contain spaces. Also, Java virtual machine isn't a valid package name to be imported in a class. The package name to be imported cannot contain spaces. Option C is incorrect because a package statement should be placed before an import statement. Option is incorrect. #package and $import aren't valid statements or directives in Java. Option F is incorrect; Java is case sensitive, so the word Class is not the same as the word class. The correct keyword to define a class is class. Given the following contents of the Java source code file myclass.java, select the correct options. Answer; B, C. Explanation: You can define multiple classes, interfaces, and enums in a Java source code file. Option, A is incorrect.
The import statement applies to all the classes, interfaces, and enums defined within the same Java source code file. Option, D is incorrect. If a package statement is defined in the source code file, all of the classes, interfaces, and enums defined within it will exist in the same Java package. Given the following definition of the class EJavaGuru, what is the output of the previous class, if it's executed using the command: Java EJavaGuru one, two, three, four? Answer, D. Explanation: The command line arguments passed to the main method of a class do not contain the word Java in the name of the class. Because the position of an array is zero based, the method argument is assigned the following values. Which of the following options when inserted at //INSERT CODE HERE will print out E JavaGuru? Answer, C. Explanation: Option A is incorrect. This option defines a valid method, but not a valid main method. The main method should be defined as a static method which is missing from the method declaration in option A.
Option B is incorrect. This option is similar to the method defined in option A with one difference. In this option, the square brackets are placed after the name of the method argument. The main method accepts an array as a method argument, and to define an array, the square brackets can be placed after either the data type or the method argument name. Option C is correct. extra spaces in a class are ignored by the Java compiler. Option D is incorrect. The main method accepts an array of string as a method argument. The method in this option accepts a single string object. Option C is incorrect. It isn't a valid method definition and doesn't specify the return type of the method. This line of code will not compile. Select the correct options. Answer, A, C. Explanation: The Java virtual machine calls and executes the main method. A class, Course is defined in a package, com.ejavaguru.
Given that the physical location of the corresponding class file is /mycode/com/ejavaguru/Course.class and execution takes place within the mycode directory, which of the following lines of code, when inserted at ///INSERT CODE HERE, will import the Course class into the class MyCourse? Answer, B. Explanation: Option A is incorrect. The path of the imported class used in an import statement isn't related to the classes' physical location, it reflects the package and sub package that a class is in. Option, C and E are incorrect. The classes' physical location isn't specified in the import statement. Options D and F are incorrect, ejavagguru is a package. To import a package and its members, the package name should be followed by .*. Examine the following code. Which of the following statements will be true? Answer, C. Explanation: If the variable courseName is defined as a private member, it won't be accessible from the class EJavaGuru. An attempt to do so will cause it to fail at compile time, because the code won't compile, it can't execute. Given the following definition of the class Course. Answer, C.
Explanation: The class will fail to compile because a non-public class cannot be accessed outside a package in which it is defined. The class Course, therefore, can't be accessed from within the class EJavaGuru, even if it's explicitly imported into it. If the class itself isn't accessible, there's no point in accessing a public member of a class. Given the following code, select the correct options. Answer, A. Explanation: You can't add an explicit accessibility keyword to the method parameters. If you do, the code won't compile. So, that's it. Hope to see you in our next lesson. Have a nice day.
OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.