Last Updated on July 9, 2023 by KnownSense
31. What is operator precedence in java?
Java provides a set of rules and regulations for particularly specifying the order in which operators are evaluated. If the expression has many numbers of operators then the operator precedence comes into action. This operator precedence evaluates the operators present in the expressions based on the priority. For example, multiplication has the highest priority when compared to addition and subtraction.
32. What is the difference between ++a and a++ increment operators?
++a is a prefix increment and a++ is the postfix increment. The prefix increment is used to return the value after incrementing the present value. Whereas in postfix increment, the value is returned before incrementing it.
33. What is ternary operator in java?
Ternary operator in Java is used to replace the if-else statement. The representation or the syntax for the ternary operator is given as:
variable= (expression) ? expression true : expression false
34. What are the advantages of packages in java?
The following are the advantages of packages in Java, and they are:
- Name clashes are avoided using packages
- Packages enable easier access control
- Packages provide an effective and easier way to locate the related classes.
35. What are jump statements in java?
In Java, jump statements are mainly used to transfer control to another part of our program depending on the condition. Moreover, these statements are used to jump directly to other statements.
Break and Continue are the two jump statements present in Java.
36. What are different type of iterative statements?
The iterative statements in Java are also called looping statements, these statements are the set of statements that repeat continuously until the condition for the termination is not met.
Looping/iterative statements in Java include:
- For loop
- While loop
- Do-while loop
37.What is the difference between object –oriented and object-based language?
An object-based programming language provides the most effective way to follow all the features of OOPs concepts except inheritance. VBScript and JavaScript are examples of Object-based programming languages. Whereas Object-oriented programming language supports all the features of OOPs concepts and examples of Object-oriented programming language is Java, Python, and so on.
38. Can we declare a constructor as final?
No, We can not declare the constructor as final, if we declare it as final compiler throws a “modified final not allowed” error.
39. What happens if a method is declared static?
If we declare a method as static, the following operations take place, and they are:
- A static method can be invoked without creating an instance of the class.
- Static method can access only static data members and can change the value of a particular data member.
- In most of the cases static method belongs to the class rather than the object of the class.
40. Why is main method static in java?
The main reason is that the object is not required to call for a static method so, if we declare the main method as non-static we need to create an object first and then call the main() method. In order to save memory, we declare the main method as static in Java.
Authored by codingknownsense.com