SlideShare ist ein Scribd-Unternehmen logo
1 von 3
1- Create a class called Point that includes two instance variables as follows: An x coordinate
and a y coordinate of type integers, which are defined as private. A) Write two constructors for
this class as follows: A default constructor that sets the instance variables to zero and a
constructor that receives values for the instance variables and sets them. B) Write the set and get
methods for the Point class to set and return the values of it instance variables. C) Write a
toString() method for the Point that prints the class name (Point) and the value of its instance
variables.
Solution
Desired Program with proper comments are given below:
//Point class
public class Point
{
//private member variables
private int x_coordinates;
private int y_coordinates;
//default constructor
public Point()
{
x_coordinates = 0;
y_coordinates = 0;
}
//parameterised constructor
public Point(int x, int y)
{
x_coordinates = x;
y_coordinates = y;
}
//getter methods
public int getXCoordinates()
{
return x_coordinates;
}
public int getYCoordinates()
{
return y_coordinates;
}
//setter methods
public setXCoordinates(int x)
{
x_coordinates = x;
}
public setYCoordinates(int y)
{
y_coordinates = y;
}
}
//class to test the Point class
public class TestPointClass
{
public static void main(String[] args)
{
// creating Point class object and calling its methods
Point p1 = new Point();
Point p2 = new Point(10, 20);
System.out.println("The x_coordinates is: " + p2.getXCoordinates());
System.out.println("The y_coordinates is: " + p2.getYCoordinates());
p2.setXCoordinates(30);
p2.setYCoordinates(40);
System.out.println("The x_coordinates is: " + p2.getXCoordinates());
System.out.println("The y_coordinates is: " + p2.getYCoordinates());
}
}
1- Create a class called Point that includes two instance variables as.docx

Weitere ähnliche Inhalte

Ähnlich wie 1- Create a class called Point that includes two instance variables as.docx

Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6sotlsoc
 
Unit 1 Part - 3 constructor Overloading Static.ppt
Unit 1 Part - 3  constructor Overloading Static.pptUnit 1 Part - 3  constructor Overloading Static.ppt
Unit 1 Part - 3 constructor Overloading Static.pptDeepVala5
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined MethodPRN USM
 
Csphtp1 09
Csphtp1 09Csphtp1 09
Csphtp1 09HUST
 
Csphtp1 06
Csphtp1 06Csphtp1 06
Csphtp1 06HUST
 
Java căn bản - Chapter4
Java căn bản - Chapter4Java căn bản - Chapter4
Java căn bản - Chapter4Vince Vo
 
Chapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part IChapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part IEduardo Bergavera
 
Learning C++ - Class 4
Learning C++ - Class 4Learning C++ - Class 4
Learning C++ - Class 4Ali Aminian
 
Lecture 2 - Classes, Fields, Parameters, Methods and Constructors
Lecture 2 - Classes, Fields, Parameters, Methods and ConstructorsLecture 2 - Classes, Fields, Parameters, Methods and Constructors
Lecture 2 - Classes, Fields, Parameters, Methods and ConstructorsSyed Afaq Shah MACS CP
 
Oops concept in c#
Oops concept in c#Oops concept in c#
Oops concept in c#ANURAG SINGH
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4dplunkett
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp PresentationVishwa Mohan
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7Vince Vo
 
Constructor and Destructor.pdf
Constructor and Destructor.pdfConstructor and Destructor.pdf
Constructor and Destructor.pdfMadnessKnight
 
Make two classes called Points and Lines- Class points should have the.docx
Make two classes called Points and Lines- Class points should have the.docxMake two classes called Points and Lines- Class points should have the.docx
Make two classes called Points and Lines- Class points should have the.docxsngyun4t79
 

Ähnlich wie 1- Create a class called Point that includes two instance variables as.docx (20)

Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6
 
Unit 1 Part - 3 constructor Overloading Static.ppt
Unit 1 Part - 3  constructor Overloading Static.pptUnit 1 Part - 3  constructor Overloading Static.ppt
Unit 1 Part - 3 constructor Overloading Static.ppt
 
Getters_And_Setters.pptx
Getters_And_Setters.pptxGetters_And_Setters.pptx
Getters_And_Setters.pptx
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined Method
 
Csphtp1 09
Csphtp1 09Csphtp1 09
Csphtp1 09
 
3433 Ch09 Ppt
3433 Ch09 Ppt3433 Ch09 Ppt
3433 Ch09 Ppt
 
Ch03
Ch03Ch03
Ch03
 
Ch03
Ch03Ch03
Ch03
 
Csphtp1 06
Csphtp1 06Csphtp1 06
Csphtp1 06
 
Java căn bản - Chapter4
Java căn bản - Chapter4Java căn bản - Chapter4
Java căn bản - Chapter4
 
Chapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part IChapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part I
 
Learning C++ - Class 4
Learning C++ - Class 4Learning C++ - Class 4
Learning C++ - Class 4
 
Lecture 2 - Classes, Fields, Parameters, Methods and Constructors
Lecture 2 - Classes, Fields, Parameters, Methods and ConstructorsLecture 2 - Classes, Fields, Parameters, Methods and Constructors
Lecture 2 - Classes, Fields, Parameters, Methods and Constructors
 
Oops concept in c#
Oops concept in c#Oops concept in c#
Oops concept in c#
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
C++ L11-Polymorphism
C++ L11-PolymorphismC++ L11-Polymorphism
C++ L11-Polymorphism
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7
 
Constructor and Destructor.pdf
Constructor and Destructor.pdfConstructor and Destructor.pdf
Constructor and Destructor.pdf
 
Make two classes called Points and Lines- Class points should have the.docx
Make two classes called Points and Lines- Class points should have the.docxMake two classes called Points and Lines- Class points should have the.docx
Make two classes called Points and Lines- Class points should have the.docx
 

Mehr von jbarbara1

1- Define computer crime and list several examples of computer crime-.docx
1- Define computer crime and list several examples of computer crime-.docx1- Define computer crime and list several examples of computer crime-.docx
1- Define computer crime and list several examples of computer crime-.docxjbarbara1
 
1- Create a Visual Calculator by using winform application in Microsof.docx
1- Create a Visual Calculator by using winform application in Microsof.docx1- Create a Visual Calculator by using winform application in Microsof.docx
1- Create a Visual Calculator by using winform application in Microsof.docxjbarbara1
 
1- Consulting a periodic table- Which of the six cations studied are f.docx
1- Consulting a periodic table- Which of the six cations studied are f.docx1- Consulting a periodic table- Which of the six cations studied are f.docx
1- Consulting a periodic table- Which of the six cations studied are f.docxjbarbara1
 
1- Briefly state the difference between single stage and multistage di.docx
1- Briefly state the difference between single stage and multistage di.docx1- Briefly state the difference between single stage and multistage di.docx
1- Briefly state the difference between single stage and multistage di.docxjbarbara1
 
1- A polar section of a molecule- which is---Select--- to water- is ca.docx
1- A polar section of a molecule- which is---Select--- to water- is ca.docx1- A polar section of a molecule- which is---Select--- to water- is ca.docx
1- A polar section of a molecule- which is---Select--- to water- is ca.docxjbarbara1
 
1) Is technology the critical driver of globalization- 2) What is the.docx
1) Is technology the critical driver of globalization- 2) What is the.docx1) Is technology the critical driver of globalization- 2) What is the.docx
1) Is technology the critical driver of globalization- 2) What is the.docxjbarbara1
 
1) What creates the US federal government-wide financial statements- 2.docx
1) What creates the US federal government-wide financial statements- 2.docx1) What creates the US federal government-wide financial statements- 2.docx
1) What creates the US federal government-wide financial statements- 2.docxjbarbara1
 
1) describe how temperature influenced what materials condensed from t.docx
1) describe how temperature influenced what materials condensed from t.docx1) describe how temperature influenced what materials condensed from t.docx
1) describe how temperature influenced what materials condensed from t.docxjbarbara1
 
1- People- places- things- ideas and forces are what part of speech- V.docx
1- People- places- things- ideas and forces are what part of speech- V.docx1- People- places- things- ideas and forces are what part of speech- V.docx
1- People- places- things- ideas and forces are what part of speech- V.docxjbarbara1
 
1- In the context of DNS (a) What are the Resource Records- RR- (b) Wh.docx
1- In the context of DNS (a) What are the Resource Records- RR- (b) Wh.docx1- In the context of DNS (a) What are the Resource Records- RR- (b) Wh.docx
1- In the context of DNS (a) What are the Resource Records- RR- (b) Wh.docxjbarbara1
 
1- How are budgets used for a company or in government- What would you.docx
1- How are budgets used for a company or in government- What would you.docx1- How are budgets used for a company or in government- What would you.docx
1- How are budgets used for a company or in government- What would you.docxjbarbara1
 
1- How are temperature and heat different concepts- 2- How does the sp.docx
1- How are temperature and heat different concepts- 2- How does the sp.docx1- How are temperature and heat different concepts- 2- How does the sp.docx
1- How are temperature and heat different concepts- 2- How does the sp.docxjbarbara1
 
1- According to the career opportunities on their websites- what are s.docx
1- According to the career opportunities on their websites- what are s.docx1- According to the career opportunities on their websites- what are s.docx
1- According to the career opportunities on their websites- what are s.docxjbarbara1
 
Which is the stronger acid in the following pair- Explain your reasoni.docx
Which is the stronger acid in the following pair- Explain your reasoni.docxWhich is the stronger acid in the following pair- Explain your reasoni.docx
Which is the stronger acid in the following pair- Explain your reasoni.docxjbarbara1
 
Which is NOT true for solute retention- A) Retention time- tr- is the.docx
Which is NOT true for solute retention- A) Retention time- tr- is the.docxWhich is NOT true for solute retention- A) Retention time- tr- is the.docx
Which is NOT true for solute retention- A) Retention time- tr- is the.docxjbarbara1
 
Which form type displays records in a tabular format similar to a Data.docx
Which form type displays records in a tabular format similar to a Data.docxWhich form type displays records in a tabular format similar to a Data.docx
Which form type displays records in a tabular format similar to a Data.docxjbarbara1
 
which equation best represents the net ionic reaction that occurs when.docx
which equation best represents the net ionic reaction that occurs when.docxwhich equation best represents the net ionic reaction that occurs when.docx
which equation best represents the net ionic reaction that occurs when.docxjbarbara1
 
Which complex in the electron transport chain does not contribute to t.docx
Which complex in the electron transport chain does not contribute to t.docxWhich complex in the electron transport chain does not contribute to t.docx
Which complex in the electron transport chain does not contribute to t.docxjbarbara1
 
where heat is transfer high in conduction or convection where heat i.docx
where heat is transfer high in conduction or convection   where heat i.docxwhere heat is transfer high in conduction or convection   where heat i.docx
where heat is transfer high in conduction or convection where heat i.docxjbarbara1
 
Where do most college students exist on Maslow-'s hierarchy of needs-.docx
Where do most college students exist on Maslow-'s hierarchy of needs-.docxWhere do most college students exist on Maslow-'s hierarchy of needs-.docx
Where do most college students exist on Maslow-'s hierarchy of needs-.docxjbarbara1
 

Mehr von jbarbara1 (20)

1- Define computer crime and list several examples of computer crime-.docx
1- Define computer crime and list several examples of computer crime-.docx1- Define computer crime and list several examples of computer crime-.docx
1- Define computer crime and list several examples of computer crime-.docx
 
1- Create a Visual Calculator by using winform application in Microsof.docx
1- Create a Visual Calculator by using winform application in Microsof.docx1- Create a Visual Calculator by using winform application in Microsof.docx
1- Create a Visual Calculator by using winform application in Microsof.docx
 
1- Consulting a periodic table- Which of the six cations studied are f.docx
1- Consulting a periodic table- Which of the six cations studied are f.docx1- Consulting a periodic table- Which of the six cations studied are f.docx
1- Consulting a periodic table- Which of the six cations studied are f.docx
 
1- Briefly state the difference between single stage and multistage di.docx
1- Briefly state the difference between single stage and multistage di.docx1- Briefly state the difference between single stage and multistage di.docx
1- Briefly state the difference between single stage and multistage di.docx
 
1- A polar section of a molecule- which is---Select--- to water- is ca.docx
1- A polar section of a molecule- which is---Select--- to water- is ca.docx1- A polar section of a molecule- which is---Select--- to water- is ca.docx
1- A polar section of a molecule- which is---Select--- to water- is ca.docx
 
1) Is technology the critical driver of globalization- 2) What is the.docx
1) Is technology the critical driver of globalization- 2) What is the.docx1) Is technology the critical driver of globalization- 2) What is the.docx
1) Is technology the critical driver of globalization- 2) What is the.docx
 
1) What creates the US federal government-wide financial statements- 2.docx
1) What creates the US federal government-wide financial statements- 2.docx1) What creates the US federal government-wide financial statements- 2.docx
1) What creates the US federal government-wide financial statements- 2.docx
 
1) describe how temperature influenced what materials condensed from t.docx
1) describe how temperature influenced what materials condensed from t.docx1) describe how temperature influenced what materials condensed from t.docx
1) describe how temperature influenced what materials condensed from t.docx
 
1- People- places- things- ideas and forces are what part of speech- V.docx
1- People- places- things- ideas and forces are what part of speech- V.docx1- People- places- things- ideas and forces are what part of speech- V.docx
1- People- places- things- ideas and forces are what part of speech- V.docx
 
1- In the context of DNS (a) What are the Resource Records- RR- (b) Wh.docx
1- In the context of DNS (a) What are the Resource Records- RR- (b) Wh.docx1- In the context of DNS (a) What are the Resource Records- RR- (b) Wh.docx
1- In the context of DNS (a) What are the Resource Records- RR- (b) Wh.docx
 
1- How are budgets used for a company or in government- What would you.docx
1- How are budgets used for a company or in government- What would you.docx1- How are budgets used for a company or in government- What would you.docx
1- How are budgets used for a company or in government- What would you.docx
 
1- How are temperature and heat different concepts- 2- How does the sp.docx
1- How are temperature and heat different concepts- 2- How does the sp.docx1- How are temperature and heat different concepts- 2- How does the sp.docx
1- How are temperature and heat different concepts- 2- How does the sp.docx
 
1- According to the career opportunities on their websites- what are s.docx
1- According to the career opportunities on their websites- what are s.docx1- According to the career opportunities on their websites- what are s.docx
1- According to the career opportunities on their websites- what are s.docx
 
Which is the stronger acid in the following pair- Explain your reasoni.docx
Which is the stronger acid in the following pair- Explain your reasoni.docxWhich is the stronger acid in the following pair- Explain your reasoni.docx
Which is the stronger acid in the following pair- Explain your reasoni.docx
 
Which is NOT true for solute retention- A) Retention time- tr- is the.docx
Which is NOT true for solute retention- A) Retention time- tr- is the.docxWhich is NOT true for solute retention- A) Retention time- tr- is the.docx
Which is NOT true for solute retention- A) Retention time- tr- is the.docx
 
Which form type displays records in a tabular format similar to a Data.docx
Which form type displays records in a tabular format similar to a Data.docxWhich form type displays records in a tabular format similar to a Data.docx
Which form type displays records in a tabular format similar to a Data.docx
 
which equation best represents the net ionic reaction that occurs when.docx
which equation best represents the net ionic reaction that occurs when.docxwhich equation best represents the net ionic reaction that occurs when.docx
which equation best represents the net ionic reaction that occurs when.docx
 
Which complex in the electron transport chain does not contribute to t.docx
Which complex in the electron transport chain does not contribute to t.docxWhich complex in the electron transport chain does not contribute to t.docx
Which complex in the electron transport chain does not contribute to t.docx
 
where heat is transfer high in conduction or convection where heat i.docx
where heat is transfer high in conduction or convection   where heat i.docxwhere heat is transfer high in conduction or convection   where heat i.docx
where heat is transfer high in conduction or convection where heat i.docx
 
Where do most college students exist on Maslow-'s hierarchy of needs-.docx
Where do most college students exist on Maslow-'s hierarchy of needs-.docxWhere do most college students exist on Maslow-'s hierarchy of needs-.docx
Where do most college students exist on Maslow-'s hierarchy of needs-.docx
 

Kürzlich hochgeladen

ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 

Kürzlich hochgeladen (20)

ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 

1- Create a class called Point that includes two instance variables as.docx

  • 1. 1- Create a class called Point that includes two instance variables as follows: An x coordinate and a y coordinate of type integers, which are defined as private. A) Write two constructors for this class as follows: A default constructor that sets the instance variables to zero and a constructor that receives values for the instance variables and sets them. B) Write the set and get methods for the Point class to set and return the values of it instance variables. C) Write a toString() method for the Point that prints the class name (Point) and the value of its instance variables. Solution Desired Program with proper comments are given below: //Point class public class Point { //private member variables private int x_coordinates; private int y_coordinates; //default constructor public Point() { x_coordinates = 0; y_coordinates = 0; } //parameterised constructor public Point(int x, int y) { x_coordinates = x; y_coordinates = y; } //getter methods public int getXCoordinates() {
  • 2. return x_coordinates; } public int getYCoordinates() { return y_coordinates; } //setter methods public setXCoordinates(int x) { x_coordinates = x; } public setYCoordinates(int y) { y_coordinates = y; } } //class to test the Point class public class TestPointClass { public static void main(String[] args) { // creating Point class object and calling its methods Point p1 = new Point(); Point p2 = new Point(10, 20); System.out.println("The x_coordinates is: " + p2.getXCoordinates()); System.out.println("The y_coordinates is: " + p2.getYCoordinates()); p2.setXCoordinates(30); p2.setYCoordinates(40); System.out.println("The x_coordinates is: " + p2.getXCoordinates()); System.out.println("The y_coordinates is: " + p2.getYCoordinates()); } }