Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Write a program to print the area of a rectangle by creating a class named 'Area'
having two methods. First method named as 'setDim' takes length and breadth of
rectangle as parameters and the second method named as 'getArea' returns the area of
the rectangle. Length and breadth of rectangle are entered through keyboard.
2. Write a program that would print the information (name, year of joining, salary,
address) of three employees by creating a class named 'Employee'. The output should
be as follows:
Name Year of joining Address
Robert 1994 64C- WallsStreat
Sam 2000 68D- WallsStreat
John 1999 26B- WallsStreat
3. Create a class named 'Rectangle' with two data members- length and breadth and a
method to claculate the area which is 'length*breadth'. The class has three constructors
which are :
1 - having no parameter - values of both length and breadth are assigned zero.
2 - having two numbers as parameters - the two numbers are assigned as length and
breadth respectively.
3 - having one number as parameter - both length and breadth are assigned that number.
Now, create objects of the 'Rectangle' class having none, one and two parameters and
print their areas.
4. Create an abstract class 'Bank' with an abstract method 'getBalance'. $100, $150 and
$200 are deposited in banks A, B and C respectively. 'BankA', 'BankB' and 'BankC'
are subclasses of class 'Bank', each having a method named 'getBalance'. Call this
method by creating an object of each of the three classes.
5. package exercise
Create a package called exercises and inside that a subpackage called java .
In the java package create a class called DataObject .
Inside the DataObject class create a public member variable called count of
type int .
Inside the main() method create an array of DataObject.
Create 3 DataObject instances and assign a reference to them to element 0,1
and 2 in the array.
Inside the main() method create a sum variable of type int .
Loop through the array and add all count member variable values of the
DataObject instances to the sum variable.
Inside the main() method, insert a System.out.println() statement that prints
out the value of the sum variable.
6. Find the output of the following
class Main {
public static void main(String args[]) {
System.out.println(fun());
}
int fun() {
return 20;
}
}
7. Find the output of the following
public class A {
public static void main(String[] args)
{
System.out.println('j' + 'a' + 'v' + 'a');
}
}
8. Find the output
class Q1{
System.out.print(x+s);
}}