Interview Questions, Answers and Tutorials

Month: August 2018

11 Constructors & Enum

11.1 | Constructors   Constructor declarations are similar to method declarations. However, the constructors’ names must be the same as the class name and it cannot return a value. The main objective of a constructor is to set the initial state of an object. When the object is created by using the new operator. The following code shows how to declare constructors with and without input parameters.       11.2 | ENUM   Enum is a Java keyword used to represent a fixed number of well-known values. For example, the number of days in a week, the number of Read More

10 Class and Methods

10.1 | Class A class is a template from which objects are created. A class declaration typically contains a set of attributes (instance variables) and functions (methods).     10.2 | Methods In Java, functions, and procedures are called methods. Methods can include zero or more input parameters and zero or one return parameter. The following code shows some method declarations. An arithmetic class has two methods printSum and getSum. method printSum has two input parameters both of integer type and no return parameter. while method getSum has two integer type input parameters and one integer type return parameter.       Read More

09.3 Control Flow

9.3 | Transfer Statement Java provides six language constructs to transfer control or exit loops in a program. break continue return try …catch …finally throw assert   break …statement   break …statement terminates a loop.   For example, the following code showed how to terminate a while and for a loop.   continue …statement continue …statement exits the current iteration and starts executing the next iteration. For example, the following code prints all numbers except number 3. return …statement return …statement stops code execution of a method and transfer control back to the calling code. try …catch …finally …statement try Read More