Professional Documents
Culture Documents
sum=sum+k;
}
System.out.println(k);
System.out.println(sum);
}
System.out.println(ctr);
}
10.int x=15,y=10,z=25;
int var=x>y&&x>z?x:y>z?y:z;
System.out.println(var);
System.out.println(Math.max(-9.7567,8.12));
System.out.println(Math.sqrt(16));
System.out.println(Math.pow(4,2));
System.out.println(Math.rint(9.7567));
17 a).Illustrate a default constructor for a class when an object of the class is created
and initialize the object data members with known variables.
public class digit
{
private int a,b;
}
b) What is meant by a literal and an identifier? Give an example?
houseRent=h; }
} void gross ()
float netSal ( ) {
{ float g;
float nSal=basicSal+ houseRent; g= netSal() +travelAllow;
return nSal; System.out.println(g);
} }
} }
1.Write the name of the base class and the derived class
2.What will be the out put if the values of s,h and t are 100,50 and 40 respectively
3.What is the function of super and extends
19 )Write the result of:
x-y+x/(y * Math.pow(x,2)) *2
when x=10, y=2
20 a)) Write the conditional statement that compares string str with string constant “ I
AM PROUD TO BE AN INDIAN “ .
b) Identify the error in the following statement and correct it.
Short number= =2;
s *=a;
a+=1;
}
return s;
}
22)The following program prints the integer codes (ascii code) of a character. Fill in the
blanks numbered 1-5 so that the program works correctly.
Class Fill
{
_______1__ convert(char c)
{
_____2____ d=c;
System.out.println(d);
}
7
23)What is an infinite loop?Write a for loop statement that initializes a loop variable i
as 100,decrements it by 1 in every pass and executes the loop body infinite no of
times.
24)Define a method extract to extract m number of characters beginning from the nth
index in the string
25)Write a class that has a method to accept the profit and cost price as parameters and
calculate the profit percent using the formula
Profitpercent=profit/cost price*100
Where profit=selling price-cost price
26)class test
{
int num;
void func()
{
int num;
num=5;
}}
(i)In the above function to which variable is the value 5 assigned ?Is it assigned to local
num or instance variable num?
(ii)Write the line inside func() to assign value 5 to the instance variable num
(int p)
27)Read the following class and answer the questions that follow:-
class Ac
{
float x(int p,int q)
{
return p%q;
}
}
(i)Define an overloaded function in the class that returns the quotient of 2 numbers
(ii)Define the integer data members n1 and n2 in the class.Initialise them with the values in
the default constructor.
28)char chars[]={‘p’,’q’,’r’};
8
}
33)How many types of variables can be defined in a class?
In the class given below categorise the variables according to their types.
class Student1
{
private int rollno;
String name;
static String month;
void getData(String n,int r, String m)
{ rollno=r;
name=n;
month=m;
String sm=rollno+name;
}}
34)class PayRoll
{
public void m()
{
long hoursworked=40;
double pay=10.0,tax=0.10;
System.out.println(“hours worked “+hoursworked);
System.out.println((hoursworked *pay-tax));
}
}
(i)Modify each variable such that the variables are declared and not initialized.Write 3
assignment statements to assign a value to each variable.
(ii)What happens when one of the initializations is removed?
(iii) What happens when one of the declarations is removed?
iv) Can we access the variables pay and tax in the method disp if disp () is defined in the
same class.
.35)Identify the error and rewrite the correct statement
(a) for(int i=1;i<5;i++);
System.out.println(i+2);
(b)class errors
{
10
int x;
double y;
private void errors( )//default constructor
{
x=2.3;
y=34;
}