Question

In: Computer Science

Need urgently, please do it as soon as possible i have only 40 min for this...

Need urgently, please do it as soon as possible i have only 40 min for this task ( Doing in Java).

Question no 1: Solve completely.

a) Define the following concepts with proper syntax, where required. Also, write why we use these concepts (for last three bullets).

 Execution process of java program

 Copy constructor

 Instance and class variable

 Access specifiers

b) Write a program to print the area of a rectangle by creating a class named 'Area' having two methods. First method named as 'setDim' takes length and breadth of rectangle as parameters and the second method named as 'getArea' returns the area of the rectangle. Length and breadth of rectangle are passed through constructor.

Solutions

Expert Solution

a) Execution process of java program

Java file (for eg: abc.java) is executed as follows:

  1. Java file (for eg: abc.java) is first compiled to check for syntax and any other errors.
  2. If unfound any errors, Java compiler javac converts to intermediate code (abc.class) called bytecode.
  3. This byte code is platform independent and can run on any operating system but can be understandable by JVM(Java Virtual Machine)
  4. Class loader in the JVM loads this bytecode into JVM
  5. Bytecode verifier in JVM passes to interpreter and and convert each line of bytecode to machine code which is executable . This machine code is passed to CPU to execute the process.

Copy constructor

  • No copy constructor in java
  • It is used to copy an object to another object
public class Data {     
    
    String name;    
    Data( String d_name)
    {
        name=d_name;
    }
    //Creating copy constructor that copies the value of oneobject to another.
    
    Data (Data d)
    {
        name=d.name;
    }
    //Printing value
    void show()
    {
        System.out.println(" Name: "+name);
    }    
    public static void main(String[] args) {
     Data d1=new Data("abc");

     //Passing object as parameter 
     Data d2= new Data(d1);
     d1.show();
     d2.show();
     
        
}
}

Instance and class variable

Instance variable are declared outside method or constructor but inside a class. Changes in variables by one object doesnot reflect other objects.

Class variable is declared with keyword static but outside constructor or method. Class variable is also called static variable. Changes made in variable by one object may change by other object.

Access Specifier

Regulates the accessibilty of class ,constructor and methods.

Four type of access specifier are:

  • public
  • private
  • protected
  • default

public: Can be accessed outside the class. Constructor or method can also declared as public.

public class File{// public class
    
public name; //public instance variable


}

private: Can be accessed within class only. Hide data from outside world as encapsulation.

protected: Can be declared with method or constructor but not in class.

public class File{


protected void show(){
          System.out.println("abc ");

}
}

default: Can be accessed within package but not outside.

b)

public class Area {
    
    private int len;
    private int bd;
    //Creating constructor and assigning values 
    Area(int length, int breadth)
    {
        len=length;
        bd=breadth;
    }
    //setter to set variables
    public void setDim(int length,int breadth)
    {
        len=length;
        bd=breadth;
    }
    //Function to calculate area of rectangle
    public int getArea()
    {
        return len*bd;
    }
            
    public static void main(String[] args) {
        
        //Creating object and passing value to constructor
        Area a1=new Area(10,20);
        //Printing area by invoking function getArea()
        System.out.println("Area of Rectangle is " + a1.getArea());
        
    }
    
}

Screenshot

Output


Related Solutions

I need this as soon as possible, please. It is due two hours and I need...
I need this as soon as possible, please. It is due two hours and I need to check my answers. Problem-1 Calculate the Product of the following using refined multiplication method (show all steps in table)                                                                 6 X 3 Problem-2 Calculate the Product of the following using Booth’s Multiplication Algorithm (show all steps in table) 5 X (-4) (-3) X (-6)
Please answer as soon as possible, I will upvote if it is answered in 40 minutes....
Please answer as soon as possible, I will upvote if it is answered in 40 minutes. Suppose that a bond portfolio with a duration of 5 years is hedged using a futures contract in which the underlying asset has a duration of 14 years. What is likely to be the impact on the hedge of the fact that the 14-year rate is less volatile than the 5-year rate?
i REALLY NEED REPLY AS SOON AS POSSIBLE: PLEASE PLEASE MAKE THE ASSIGNMENT ON THIS TASK...
i REALLY NEED REPLY AS SOON AS POSSIBLE: PLEASE PLEASE MAKE THE ASSIGNMENT ON THIS TASK OF Business Ideas based on a indian restaurants Purpose: Develop and formulate an idea for your own business. Money is not an issue for this assignment. Envision that you get all the funding you need to start it up. Task: Write a short abstract (200-250 Words) describing your business idea in the discussion section of this assignment. What is the basic idea? What are...
i REALLY NEED REPLY AS SOON AS POSSIBLE: PLEASE PLEASE MAKE THE ASSIGNMENT ON THIS TASK...
i REALLY NEED REPLY AS SOON AS POSSIBLE: PLEASE PLEASE MAKE THE ASSIGNMENT ON THIS TASK OF Business Ideas based on a indian restaurants Purpose: THIS IS THE QUESTION : Develop and formulate an idea for your own business. Money is not an issue for this assignment. Envision that you get all the funding you need to start it up. Task: Write a short abstract (200-250 Words) describing your business idea in the discussion section of this assignment. What is...
i REALLY NEED REPLY AS SOON AS POSSIBLE: PLEASE PLEASE MAKE THE ASSIGNMENT ON THIS TASK...
i REALLY NEED REPLY AS SOON AS POSSIBLE: PLEASE PLEASE MAKE THE ASSIGNMENT ON THIS TASK OF Business Ideas based on a indian restaurants Purpose: Develop and formulate an idea for your own business. Money is not an issue for this assignment. Envision that you get all the funding you need to start it up. Task: Write a short abstract (200-250 Words) describing your business idea in the discussion section of this assignment. What is the basic idea? What are...
i REALLY NEED REPLY AS SOON AS POSSIBLE: PLEASE PLEASE MAKE THE ASSIGNMENT ON THIS TASK...
i REALLY NEED REPLY AS SOON AS POSSIBLE: PLEASE PLEASE MAKE THE ASSIGNMENT ON THIS TASK OF Business Ideas based on a indian restaurants Purpose: Develop and formulate an idea for your own business. Money is not an issue for this assignment. Envision that you get all the funding you need to start it up. Task: Write a short abstract (200-250 Words) describing your business idea in the discussion section of this assignment. What is the basic idea? What are...
Please I need The right answer for this question as soon as possible. A sag vertical...
Please I need The right answer for this question as soon as possible. A sag vertical curve (equal tangent) has PVI at station 212+00 and elevation 540.75 ft. The initial grade is -2.5% and the final grade is +4.5%. The length of the curve is 900 ft. Determine the following, 1. Stationing of the low point, PVC, and PVT. 2. Elevation at station 213+00, PVC, low point, and PVT.
I need an answer as soon as possible please...Thank you The following information relates to the...
I need an answer as soon as possible please...Thank you The following information relates to the HTM debt securities investments of Kiran Company during 2018: a.            February 1: The company purchased 9% bonds of Tempe Co. having a par value of $100,000 at 99 plus accrued interest. Interest is payable May 1 and November 1. Maturity date is 11/1/19. b.            May 1: Semiannual interest is received and amortization is updated. c.            July 1: 10% bonds of Flagstaff, Inc. were purchased....
PLEASE ANSWER #8, 9 AND 10 AS SOON AS POSSIBLE. THANK YOU IF POSSIBLE PLEASE DO...
PLEASE ANSWER #8, 9 AND 10 AS SOON AS POSSIBLE. THANK YOU IF POSSIBLE PLEASE DO WHOLE QUESTIONS. I WANT TO DOUBLE CHECK WITH MINE Required:#1.Prepare journal entries to record the December transactions in the General Journal Tab in the excel template file "Accounting Cycle Excel Template.xlsx". Use the following accounts as appropriate: Cash, Accounts Receivable, Supplies, Prepaid Insurance, Equipment, Accumulated Depreciation, Accounts Payable, Wages Payable, Common Stock, Retained Earnings, Dividends, Service Revenue, Depreciation Expense, Wages Expense, Supplies Expense, Rent...
Hello I need this assignment with citations and biography in APA style as soon as possible...
Hello I need this assignment with citations and biography in APA style as soon as possible 1. It has been found that when health care workers (physicians and nurses) do not practice healthy lifestyle behaviours, this has a negative impact on health promotion as they are less likely to encourage patients to practice healthy behavious. Locate any two validated instruments for measuring habits and personal attitudes of health care workers towards healthy lifestyle behaviours (eg not smoking, eating low risk...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT