Student

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

// Program explaining class creation

// usage of this keyword

class Name {
private String name;
private int age;

void Name(){
System.out.println("No name");
}

void setName(String name, int age) {


this.name = name;
this.age = age;
}

void show() {
System.out.println("My Name is " + name);
System.out.println("My Age is " + age);
}
}

class Address{

private String address;

void Address(){
System.out.println("No address");
}

void setAddress(String address) {


this.address = address;
}

void show() {
System.out.println("My address is " + address);
}

public class Student {

void setNameAge(){
Name name = new Name();
name.setName("Ashikin", 30);
name.show();
}

void setAddress(){
Address address = new Address();
address.setAddress("Taman Nusa Bayu");
address.show();
}

public static void main(String[]args) {


Student obj = new Student ();
obj.setNameAge();
obj.setAddress();
}
}

You might also like