Q1.What do you understand by complier error and run time error? Explain by example.
Q2. What is wrong with the following variable declarations?
int Km/h = 120;
String Newcar = GMC;
int Adouble = "50";
String newCar = "GMC"
int x = 5, y = "x";
String new Car = "GMC";
Q3. What does this sequence of statements print?
String msg = "The number of characters in newCar is";
String newCar = "GMC";
int numberOfCharacters = newCar.length();
String carUpperCase = newCar.toUpperCase();
System.out.print(newCar);
System.out.println(carUpperCase);
System.out.print(msg);
System.out.println(newCar.length());
newCar.replace("C","U");
newCar.replace("M","E");
newCar.replace("G","S");
System.out.print("Welcome to : ");
System.out.println(newCar);
/*System.out.println("Good luck");
System.out.println("to all students");*/
Q4. Consider the following class:
public class IdentifyMyParts
{
private int x = 7;
private int y = 3;
}
a. What are the instance variables?
b. What is the output from the following code:
IdentifyMyParts a = new IdentifyMyParts();
IdentifyMyParts b = new IdentifyMyParts();
a.y = 5;
b.y = 6;
a.x = 1;
b.x = 2;
System.out.println("a.y = " + a.y);
System.out.println("b.y = " + b.y);
System.out.println("a.x = " + a.x);
System.out.println("b.x = " + b.x);
Q5. What is the output of the following code:
a.
int num1 = 6;
int num2 = 10;
num1 = num1 + num2;
num2 = num1 + num2;
System.out.println(num1 + ", " + num2);
b.
int a = 10;
int b = 20;
int c = 2;
int x = b / a /*c*/;
Q6. Write a Java program that performs the following:
1. Identify the radius of the circle. (radius = 3)
2. Calculate circumference and area of the circle.
3. Print the results.