Practice Set For Basic OOPs Concept:

 

(Note: comments code and then run for each problem.)

Problems-

1. Create a class Employee with the following properties and methods:

Salary (property) (int)

getSalary (returning int)

name(property) (String)

getName(Reurning String)

setName(changing the name)


2. Create a class cellphone with methods to print ringing..., vibrating...., and calling friends....etc.

3. Create a class with a method to initiate its side, calculating area, perimeter, etc. 

-------------------------------------------------------------------------------------------------------------------

Code:


package Com.Suryawanshi;

class Employee{
int Salary;
String name;

public int getSalary(){
return Salary;
}

public String getName(){
return name;
}

public void setName(String n){
name = n ;
}
}

class CellPhone{
public void ring(){
System.out.println("Ringing........");
}

public void vibrate(){
System.out.println("Vibrating.......");
}

public void callFriend(){
System.out.println("Calling Abhay.......");
}
}

class Square{
int side;
public int squareArea(){
return side*side;
}

public int squarePerimeter(){
return 4*side;
}
}

public class PracticeSetForBasicOPPs {
public static void main(String[] args) {
// Problem 01
Employee abhay = new Employee();

abhay.setName("Abhay Suryawanshi");
System.out.println(abhay.getName());

abhay.Salary = 15000;
System.out.println(abhay.getSalary());

// Problem 02
CellPhone iphone = new CellPhone();
iphone.ring();
iphone.vibrate();
iphone.callFriend();

// Problem 03
Square sq = new Square();
sq.side = 5;
System.out.println(sq.squareArea());
System.out.println(sq.squarePerimeter());

}
}
OutPut:
Abhay Suryawanshi
15000
----------------------------
Ringing........
Vibrating.......
Calling Abhay.......
-------------------------------
25
20


Comments

Popular posts from this blog

Creating code for Rock Paper Scissors: