0% found this document useful (0 votes)
4 views3 pages

Encapsulation

The document contains a Java class named 'Demo' with private fields for age and name, along with getter and setter methods for these fields. The main method creates an instance of 'Demo', sets the age to 90 and the name to 'prerna', and then prints these values. There are also multiple instances of a 'Person' constructor that appears to have incorrect parameter types and is not properly integrated into the 'Demo' class.

Uploaded by

som22extc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Encapsulation

The document contains a Java class named 'Demo' with private fields for age and name, along with getter and setter methods for these fields. The main method creates an instance of 'Demo', sets the age to 90 and the name to 'prerna', and then prints these values. There are also multiple instances of a 'Person' constructor that appears to have incorrect parameter types and is not properly integrated into the 'Demo' class.

Uploaded by

som22extc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

public class Demo{

prtivate int age;


private String name;
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
public String getName()
{
return name ;
}
public void setName(int name)
{
this.name = name;
}
public static void main(String args[])
{
Demo obj = new Demo();
obj.setAge(90);
obj.setName("prerna");
System.out.println(obj.getAge()+" "+obj.getName());
}
}

public Person(String age ,int name)


{
this.name = name;
this.age = age;
}
public class Demo{
prtivate int age;
private String name;
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
public String getName()
{
return name ;
}
public void setName(int name)
{
this.name = name;
}
public static void main(String args[])
{
Demo obj = new Demo();
obj.setAge(90);
obj.setName("prerna");
System.out.println(obj.getAge()+" "+obj.getName());
}
}

public Person(String age ,int name)


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

public class Demo{


prtivate int age;
private String name;
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
public String getName()
{
return name ;
}
public void setName(int name)
{
this.name = name;
}
public static void main(String args[])
{
Demo obj = new Demo();
obj.setAge(90);
obj.setName("prerna");
System.out.println(obj.getAge()+" "+obj.getName());
}
}

public Person(String age ,int name)


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

public class Demo{


prtivate int age;
private String name;
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
public String getName()
{
return name ;
}
public void setName(int name)
{
this.name = name;
}
public static void main(String args[])
{
Demo obj = new Demo();
obj.setAge(90);
obj.setName("prerna");
System.out.println(obj.getAge()+" "+obj.getName());
}
}

public Person(String age ,int name)


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

public class Demo{


prtivate int age;
private String name;
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
public String getName()
{
return name ;
}
public void setName(int name)
{
this.name = name;
}
public static void main(String args[])
{
Demo obj = new Demo();
obj.setAge(90);
obj.setName("prerna");
System.out.println(obj.getAge()+" "+obj.getName());
}
}

public Person(String age ,int name)


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

You might also like