SlideShare ist ein Scribd-Unternehmen logo
1 von 3
1) Consider the following class (given as a class diagram)
Person
? int age
? String name
+ Person(String, int) + Person()
+ void speak()
Among the following statements, indicate which are valid and which are invalid. A valid
statement is a statement that compiles and executes in any class, which has access to the Person
class. If a statement is invalid, explain why. Assume that the variables p and q are of type Person
and have been correctly initialized before being used.
a) Person p = new Person(“Maryjane―, 30);
b) p.speak();
c) p.sleep();
d) Person p = new Person;
e) Person.speak();
f) Person p = new Speak();
g) p.age = 25;
h) System.out.println(“p.name―);
i) System.out.println(p.name);
j) p=q;
k) new Person(“Huy―,26).speak();
Person
? int age
? String name
+ Person(String, int) + Person()
+ void speak()
Solution
public class Person {
int age;
String name;
public static void main(String[] args)
{
Person p = new Person("Maryjane", 30);
Person q = new Person("Maryjane", 30);
p.speak();
p.sleep();
//Person p = new Person;
// Person.speak();
//Person p = new Speak();
p.age = 25;
System.out.println("p.name");
System.out.println(p.name);
p=q;
new Person("Huy",26).speak();
}
Person(){}
public Person(String string, int i) {
// TODO Auto-generated constructor stub
}
void sleep(){
}
void speak(){
}
}
invalid statement
Person p = new Person;
Person.speak();
Person p = new Speak();

Weitere ähnliche Inhalte

Mehr von jbarbara1

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
jbarbara1
 
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
jbarbara1
 
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
jbarbara1
 
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
jbarbara1
 
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
jbarbara1
 
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
jbarbara1
 
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
jbarbara1
 
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
jbarbara1
 
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
jbarbara1
 

Mehr von jbarbara1 (20)

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
 
When the sender and the recipient can transmit data to each other over.docx
When the sender and the recipient can transmit data to each other over.docxWhen the sender and the recipient can transmit data to each other over.docx
When the sender and the recipient can transmit data to each other over.docx
 
When the equity method is applied- what disclosures should be made in.docx
When the equity method is applied- what disclosures should be made in.docxWhen the equity method is applied- what disclosures should be made in.docx
When the equity method is applied- what disclosures should be made in.docx
 
When the following equation is balanced properly under acidic conditio.docx
When the following equation is balanced properly under acidic conditio.docxWhen the following equation is balanced properly under acidic conditio.docx
When the following equation is balanced properly under acidic conditio.docx
 
When should a company disclose extraordinary items on their income sta (1).docx
When should a company disclose extraordinary items on their income sta (1).docxWhen should a company disclose extraordinary items on their income sta (1).docx
When should a company disclose extraordinary items on their income sta (1).docx
 

Kürzlich hochgeladen

Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 

Kürzlich hochgeladen (20)

Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.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
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 

1) Consider the following class (given as a class diagram) Person - in.docx

  • 1. 1) Consider the following class (given as a class diagram) Person ? int age ? String name + Person(String, int) + Person() + void speak() Among the following statements, indicate which are valid and which are invalid. A valid statement is a statement that compiles and executes in any class, which has access to the Person class. If a statement is invalid, explain why. Assume that the variables p and q are of type Person and have been correctly initialized before being used. a) Person p = new Person(“Maryjane―, 30); b) p.speak(); c) p.sleep(); d) Person p = new Person; e) Person.speak(); f) Person p = new Speak(); g) p.age = 25; h) System.out.println(“p.name―); i) System.out.println(p.name); j) p=q; k) new Person(“Huy―,26).speak(); Person ? int age ? String name + Person(String, int) + Person() + void speak()
  • 2. Solution public class Person { int age; String name; public static void main(String[] args) { Person p = new Person("Maryjane", 30); Person q = new Person("Maryjane", 30); p.speak(); p.sleep(); //Person p = new Person; // Person.speak(); //Person p = new Speak(); p.age = 25; System.out.println("p.name"); System.out.println(p.name); p=q; new Person("Huy",26).speak(); } Person(){}
  • 3. public Person(String string, int i) { // TODO Auto-generated constructor stub } void sleep(){ } void speak(){ } } invalid statement Person p = new Person; Person.speak(); Person p = new Speak();