SlideShare uma empresa Scribd logo
1 de 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();

Mais conteúdo relacionado

Mais de 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.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
 
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.docxjbarbara1
 
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.docxjbarbara1
 
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.docxjbarbara1
 
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).docxjbarbara1
 

Mais de 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
 

Último

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
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 ConsultingTechSoup
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
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.pptxAreebaZafar22
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
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
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
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
 
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.pdfAdmir Softic
 
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
 
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
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 

Último (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
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
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
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
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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)
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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
 
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
 
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Ữ Â...
 
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
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 

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();