How can you create an object of a class in a package?

Answers were Sorted based on User's Feedback



How can you create an object of a class in a package?..

Answer / sh faisal

package Test;

sub new
{
$class = shift;
$self = {};

bless $self,$class; # By Mistake earlier i wrote it as
#$ref
return $self;
}
1;
# In perl Script

use Test; # Include the module you have created
$obj=new Test; # creating an onject of Class Test

Is This Answer Correct ?    4 Yes 0 No

How can you create an object of a class in a package?..

Answer / vipul dalwala

Say Pachage is My Package

package MyPackage;

sub method() {

}


Then U can create Object

$myobject = new MyPackage();

and u can call any method of object like:

$myobject->method();

Is This Answer Correct ?    3 Yes 1 No

How can you create an object of a class in a package?..

Answer / bhagwat gupta

--Like you do in any perl programme.

package PackageName;

use RelativePath::ModuleName;# The Class as per your questn
...
...

my $object = ModuleName->new();
...
...
1;

Is This Answer Correct ?    0 Yes 1 No

How can you create an object of a class in a package?..

Answer / shah faisal

package Test;

sub new
{
$class = shift;
$self = {};

bless $ref,$class;
return $ref;
}
1;
# In perl Script

use Test; # Include the module you have created
$obj=new Test; # creating an onject of Class Test

Is This Answer Correct ?    2 Yes 3 No

Post New Answer

More CGI Perl Interview Questions

How to connect to SQL server through Perl?

0 Answers  


How can the user execute a long command repeatedly without typing it again and again?

0 Answers  


what are the three groups involved in information sharing?

0 Answers  


What are the various file operations in perl. Explain with example.

0 Answers  


How will you declare a variable in perl?

0 Answers  






Assuming both a local($var) and a my($var) exist, what's the difference between ${var} and ${"var"}?

0 Answers  


What does the qq{ } operator do?

0 Answers  


How do you you check the return code of a command in perl?

0 Answers   HCL,


List the files in current directory sorted by size ?

0 Answers  


Distinguish my and local?

0 Answers  


How to read a directory in perl?

0 Answers  


How do find the length of an array?

0 Answers  


Categories