Computer Applications
Fill in the blanks to design a class:
class __________{
int l, b;
Area(int __________, int __________) {
l = __________;
b = __________;
}
}
Java Constructors
35 Likes
Answer
class Area
{
int l, b;
Area(int x, int y) {
l = x;
b = y;
}
}
Answered By
20 Likes
Related Questions
Name two ways of creating objects in a constructor.
Differentiate between the following statements:
abc p = new abc();
abc p = new abc(5,7,9);Write a program by using a class with the following specifications:
Class name — Hcflcm
Data members/instance variables:
- int a
- int b
Member functions:
- Hcflcm(int x, int y) — constructor to initialize a=x and b=y.
- void calculate( ) — to find and print hcf and lcm of both the numbers.
An electronics shop has announced a special discount on the purchase of Laptops as given below:
Category Discount on Laptop Up to ₹25,000 5.0% ₹25,001 - ₹50,000 7.5% ₹50,001 - ₹1,00,000 10.0% More than ₹1,00,000 15.0% Define a class Laptop described as follows:
Data members/instance variables:
- name
- price
- dis
- amt
Member Methods:
- A parameterised constructor to initialize the data members
- To accept the details (name of the customer and the price)
- To compute the discount
- To display the name, discount and amount to be paid after discount.
Write a main method to create an object of the class and call the member methods.