In Java, 1. Use examples to explain the benefits of Encapsulation, Inheritance,
ID: 3828227 • Letter: I
Question
In Java,
1. Use examples to explain the benefits of Encapsulation, Inheritance, and Polymorphism
2.Why we need a constructor in a class? If we don't create it, what will happen?
3.How are indefinite loops used for validating data? Why is a loop structure typically the better choice for validating data than an if statement?
4.
while(10 > 1){
System.out.println("This prints forever.");
}
Identify the problem that exists in the above while loop.
5. Why would a programmer use curly braces in the body of a do…while loop?
Explanation / Answer
3)Each loop executes for approximately predefined amount of periods, say n. If n is not defined then we call that loop as infinite loop or indefinite loop, though both are not same. Infinite loops execute forever. Using indefinite loop, you can input data repeatedly, but using if loop you can just checkered once whether the data is valid or not. Indefinite loop executes for unknown number of times.
4)In the given code segment, the while condition is comparing two constant values. And since that illness will always be true the loop will go for infinite number of times. Making use of coefficients in condition assessment is always dangerous.
5)do. while is also a loop that can have any number of instructions. To stipulate the starting and ending of the body curly braces remain used.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.