Computer Programming CS 140

Q. 1. Write Short Answer for the following Questions
a)  What does give Java its ‘write once and run anywhere’ nature?
b)  What is the difference between compile-time error and the run-time error? Is a “crash” a compile-time or run-time error?
c)  Write Java program that initialize a string with “Hello, Java!” and then change it to  “Hello,
World!”.
d)  What is the order of execution of operators in the following equation?
A=99*5+4%2/6+(18-4)*2
e)  Explain the difference between Method Overriding and Method Overloading.
f)  Write the following mathematical expressions in Java.
 =  




−1                =




g)  Differentiate Local Variables and Instance Variables.?
h)  What is the difference between object and object references?
i)  Write an Algorithm in Pseudo code for following:
Add the prices of an order of a car, a bike and 4 tyres.
Calculate the tax  and tell the customer their total, Tax = 13.6%.
j)  What do you meant by Accessor and Mutator Methods? Explain with example.?
k)  What is static method call? Explain with example.
l)  What is the difference between while and do-while loop?
m)  What is wrapper class? Explain with example.
n)  Why can’t input be read directly from System.in?
o)  Explain implicit parameter?

Q. 2. What errors does this class have? How would you fix them? Rewrite the correct version of this
class.
public class Square {
private double sideLength;
private double area;

public Square(double sideLength ){
sideLength = sideLength ;
area = sideLength * sideLength;
}

public double getArea() { return area; }

public static void main(string[] args){
Square sq = new Square(4.4);
System.out.print(“This Area of the square is:\t +sq. getArea);
}
}
Q. 3. Write and Explain the Output of the following program when user enters 63 and when he
enters 40.
import java.util.Scanner;

READ ALSO :   Israeli: Politics, Society and Culture

class NestedIfElse {
public static void main(String[] args) {
int marksObtained, passingMarks;
char grade;

passingMarks = 40;

Scanner input = new Scanner(System.in);

System.out.println(“Input marks scored by you”);

marksObtained = input.nextInt();

if (marksObtained >= passingMarks) {

if (marksObtained > 90)
grade = ‘A’;
else if (marksObtained > 75)
grade = ‘B’;
else if (marksObtained > 60)
grade = ‘C’;
else
grade = ‘D’;

System.out.println(“You passed the exam and your grade is ” + grade);
}
else {
grade = ‘F’;
System.out.println(“You failed and your grade is ” + grade);
}
}
}

Q. 4. Write a program that asks the coefficients of a quadratic equation and displays the roots of
the equation (only real roots).

PLACE THIS ORDER OR A SIMILAR ORDER WITH US TODAY AND GET AN AMAZING DISCOUNT 🙂