function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nagamanohar Kavuri 9Nagamanohar Kavuri 9 

Can some one help to create Class->Two Private Variables->Accept Parameter from Constructor to set values->New Method to show details-->Call instance of class in Dev Console

I wrote the below code,but througing the error as Constructor not defined and method doesnt exist

//Class
public class ConnectionDetails {
    Private  String  ConnectionCode;
    Private Integer Price;
   //Constructor
    public ConnectionDetails(String ConnectionCode,Integer Price) 
    {
        this.ConnectionCode='ConnectionCode'; 
        this.Price=Price;
    }
  //Method 
    Public static void  showDetails(String ConnectionCode,Integer Price)  
    {
            ConnectionDetails cd =new ConnectionDetails();  
        cd.showDetails('ConnectionCode','Price');       
    } 
    
}
Best Answer chosen by Nagamanohar Kavuri 9
GovindarajGovindaraj
Hi Nagamanohar,

Below is the modified code,
 
//Class
public class ConnectionDetails {
    Private  String  ConnectionCode;
    Private Integer Price;
   //Constructor
    public ConnectionDetails(String ConnectionCode,Integer Price) 
    {
        this.ConnectionCode='ConnectionCode'; 
        this.Price=Price;
    }
  //Method 
    Public static void showDetails(String ConnectionCode,Integer Price)  
    {
            ConnectionDetails cd =new ConnectionDetails('ConnectionCode',25); //Should include the parameters here.
            //cd.showDetails('ConnectionCode', 25); //As showDetails is a static method so we can't instantiate it.
    } 
    
}

Thanks,
Govindaraj.S

All Answers

GovindarajGovindaraj
Hi Nagamanohar,

Below is the modified code,
 
//Class
public class ConnectionDetails {
    Private  String  ConnectionCode;
    Private Integer Price;
   //Constructor
    public ConnectionDetails(String ConnectionCode,Integer Price) 
    {
        this.ConnectionCode='ConnectionCode'; 
        this.Price=Price;
    }
  //Method 
    Public static void showDetails(String ConnectionCode,Integer Price)  
    {
            ConnectionDetails cd =new ConnectionDetails('ConnectionCode',25); //Should include the parameters here.
            //cd.showDetails('ConnectionCode', 25); //As showDetails is a static method so we can't instantiate it.
    } 
    
}

Thanks,
Govindaraj.S
This was selected as the best answer
Nagamanohar Kavuri 9Nagamanohar Kavuri 9
Thankyou Gonvind..