OOPS in Java

class Pen {
    String color;
    int price;
    
    public void print() {
        System.out.println(this.color); // konsi object ne call kiya
        System.out.println(this.price);
    }
}

public class Main
{
	public static void main(String[] args) {
		Pen p1 = new Pen();
		p1.color = "blue";
		p1.price = 120;
		p1.print();
		
		Pen p2 = new Pen();
		p2.color = "black";
		p2.price = 120;
		p2.print();
	}
}

Leave a Comment