Searching...
Monday, September 10, 2018

Java 10 Create Object Using Var

September 10, 2018

Java10CreateObjectUsingVar.java
 package com.java9r;

public class Java10CreateObjectUsingVar {

public static void main(String[] args) {
var product = new Product();
product.setId(100);
product.setName("Product 1");
product.setPrice(55.2);
product.setQuantity(20);

System.out.println("Product Details");
System.out.println("Id: " + product.getId());
System.out.println("Name: " + product.getName());
System.out.println("Price: " + product.getPrice());
System.out.println("Quantity: " + product.getQuantity());


}

}


Product.java
 package com.java9r;

public class Product {
private int id;
private String name;
private double price;
private int quantity;

public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}



}

Output
Product Details
Id: 100
Name: Product 1
Price: 55.2
Quantity: 20

0 comments:

Post a Comment

ads2