Computer Applications
class perform
{
int m; String name;
perform(int x, String y)
{
m=x;
name=y;
}
void print()
{
System.out.print(name + " " + m);
}
public static void main()
{
perform ob1=new perform(95 , "Xavier");
ob1.print();
}
}
(a) Give the output of the code given above.
(b) Name the type of the constructor used.
Java Constructors
4 Likes
Answer
(a)
Output
Xavier 95
Explanation
- A
performobjectob1is created usingnew perform(95, "Xavier"). - The constructor assigns
m = 95andname = "Xavier". - The
print()method outputs thenamefollowed by spaces and thenm.
(b) The constructor perform(int x, String y) accepts arguments, hence it is a parameterized constructor.
Answered By
3 Likes
Related Questions
Give the output of the following:
(a) "ROSE".compareTo("ROJA")
(b) "DEDICATE".replace('D', 'L')
Consider the following array and answer the questions given below:
char ch [ ] = { ‘A’, ‘%’, ‘y’, ‘@’, ‘7’, ‘p’};(a) How many bytes does the array occupy?
(b) What is the output of the statement Character.isDigit(ch[4])?
Define a class with following specifications.
class name: Hotel
Member variables:
String name – stores name of customer name
long mobno – stores mobile number
int days – stores number of days customer stayed in hotel
int bill – stores customer billMember method:
void input() – input values using Scanner class methods only
void charge() – calculate bill as per the following criteriadays charge/day first 3 days 1000 Rs/ day next 4 days 900 Rs/day > 7 days 800 Rs/day bill = bill + gst (18% of bill)
void print() - Display customer name, mobile number and bill.
Invoke all the above methods in main method with the help of an object.
Define a class to accept values into a 3x3 integer array and print the product of each row elements.
Example:
3 1 2 4 2 1 5 1 2 Output:
Row 0 – 6
Row 1 – 8
Row 2 – 10