• Tidak ada hasil yang ditemukan

Object Oriented Techniques - Rama University

N/A
N/A
Protected

Academic year: 2024

Membagikan "Object Oriented Techniques - Rama University"

Copied!
14
0
0

Teks penuh

(1)

FACULTY OF ENGINEERING & TECHNOLOGY

Preeti Singh

Computer Science & Engineering

Lecture-21

BCS-503: Object Oriented Techniques

(2)

OBJECTIVES

In this PPT, you will learn to:

Constructors

Rules for creating Java constructor

(3)

CONSTRUCTORS

 Method invoked whenever an instance of a given class is created.

 Same name as the class and no return type.

 Java allocates memory for the object, initializes the instance variables and calls the constructor methods.

(4)

RULES FOR CREATING JAVA CONSTRUCTOR

 Constructor name must be the same as its class name

 A Constructor must have no explicit return type

 A Java constructor cannot be abstract, static, final, and synchronized

(5)

TYPES OF CONSTRUCTOR

 Two types of constructors

 Parameterized constructors

 Implicit constructors

(6)

CONSTRUCTORS (Contd.)

Example of Parameterized Constructors

Sdate(int m,int d,int y) { month=m;

day=d;

year=y;

System.out.println("The Date is " + m + "/" + d + "/" + y + ".");

}

public static void main(String args[]) {

Sdate S1,S2;

S1=new Sdate(11,27,1969);

S2=new Sdate(3,3,1973);

}

Parameterized

Constructor

(7)

CONSTRUCTORS (Contd.)

Example of Implicit Constructors

Sdate() {

month=11;

day=27;

year=1969;

}

public static void main(String args[]) {

Sdate S1,S2;

S1=new Sdate();

S2=new Sdate();

}

Implicit Constructors

(8)

REFERENCES

1. James Rumbaughet. al, "Object Oriented Modeling and Design", PHI

2. Grady Booch, James Rumbaugh, Ivar Jacobson, "The Unified Modeling Language User Guide", Pearson Education 3. Naughton, Schildt, "The Complete Reference JAVA2", TMH

4. Mark Priestley "Practical Object-Oriented Design with UML", TMH

5. Booch, Maksimchuk, Engle, Young, Conallen and Houstan, "Object Oriented Analysis and Design with Applications", Pearson Education

6. Pandey, Tiwari, " Object Oriented Programming with JAVA" , Acme Learning 7. https://www.javatpoint.com/java-tutorial

8. https://www.tutorialspoint.com/java/index.htm

9. https://www.tutorialspoint.com/object_oriented_analysis_design/index.htm 10. https://www.slideshare.net/niitstudentcare/

(9)

MULTIPLE CHOICE QUESTION

Multiple Choice Question:

Q1. What is the return type of Constructors?

a) int b) float c) void

d) none of the mentioned

(10)

MULTIPLE CHOICE QUESTION

Multiple Choice Question:

Q2. What is true about private constructor?

a) Private constructor ensures only one instance of a class exist at any point of time b) Private constructor ensures multiple instances of a class exist at any point of time c) Private constructor eases the instantiation of a class

d) Private constructor allows creating objects in other classes

(11)

MULTIPLE CHOICE QUESTION

Multiple Choice Question:

Q3. What is false about constructor?

a) Constructors cannot be synchronized in Java b) Java does not provide default copy constructor c) Constructor can be overloaded

d)“this” and “super” can be used in a constructor

(12)

MULTIPLE CHOICE QUESTION

Multiple Choice Question:

Q4. What is true about constructor?

a) It can contain return type

b) It can take any number of parameters c) It can have any non access modifiers d) Constructor cannot throw an exception

(13)

MULTIPLE CHOICE QUESTION

Multiple Choice Question:

Q5. What is not the use of “this” keyword in Java?

a) Passing itself to another method

b) Calling another constructor in constructor chaining

c) Referring to the instance variable when local variable has the same name d) Passing itself to method of the same class

(14)

Summary

In this PPT, you learned that:

 A constructor initializes an object when created.

Referensi

Dokumen terkait

semantic constructs (e.g., classes, attributes, operations, messages) appear at the analysis, design, and code level..  Therefore, a problem in the definition

Part 1 , Pythonic Classes via Special Methods : This part looks more deeply at object- oriented programming techniques and how we can more tightly integrate the class definitions

Debt and negative reputation claims are unenforceable : Because anyone using a public chain can create a new wallet address at any time, some kinds of communities can exist only

The Kalinga State University reserves the right to reject any and all bids, declare a failure of bidding, or not award the contract at any time prior to contract award in accordance

There was still the underlying problem, however, of A PRACTICE RUN By the time the business analyst started work, as a member of a team, on a large two year transaction processing

The contract is valid for providing services of vehicle hiring and at no point of time any or all of the Staff of Transporter shall raise a claim for employment in the Central

1 The Central Government shall, by notification, establish an Appellate Tribunal to be known as Competition Appellate Tribunal – a to hear and dispose of appeals against any direction

Local Vertical Coordinates  A local vertical coordinate system is a three-dimensional cartesian 𝑋𝑌𝑍 reference system which has its origin placed at a specific point within the project