Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1: 1.1 What is the difference between static fields and ordinary fields

ID: 3662162 • Letter: Q

Question

Question 1:

1.1 What is the difference between static fields and ordinary fields (i.e., the fields without static)?

1.2 Can static methods access non-static fields? Why?

Question 2:

What is constructor? What is the function of the constructor?

Question 3:

What is overloading?

Question 4:

Explain the concepts of class and object.

Question5:

Create a computer class and assume computers have the following fields:

String manufacture,

double price,

int year

In addition, the computer has the following methods:

void start() {

            System.out.println( manufacture + " computer starts." );

}

void process(String fileName)

{

            System.out.println( manufacture + " computer is processing " + fileName );

}

void shutdown ()

{

            System.out.println( manufacture + " computer is shut down);

}

In addition, create a constructor which is used to initialize all these three fields when we create objects. The example can be found in the slides.

Question 6:

Given an int array, write a method find the minimum number in the array.

static int findMininum(int[] arr) {

//your implemention

}

Question 7:

Assume you have already had the following implemented methods,

static double findMax(double d1, double d2);

static double findMax(double d1, double d2, double d3, double d4);

please implement the following method:

static double findMax(double d1, double d2, double d3, double d4, double d5, double d6) {

// your implementation

}

Explanation / Answer

1.1 for the static fields memory is created for only once during loading of a class.for non static fields memory is created for multiple times at the time of object creation.

1.2 no,static methods can not access the non static fields because non static varibles are particular to that object and can changes the value and we can call static function without object for that reason is that it cannot access the instance variables.

2.The constructor is similar to the method and called when an object is created.the function of the constructor is that to intialize the varibles.

3.overloading is done with in a class.overloading is nothing but the methods having the same name with diffrent signature then we can say that the methods are overloaded.

4.class is a collection of methods and variables or it is a template for an object.object is an instance of a class.from one class any number of objects are created.

5.public class Example

{

String manufacture;

double price;

int year;

public Example(String manufacture,double price,int year)

{

this.manufacture=manufacture;

this.price=price;

this.year=year;

}

    public void start() {

            System.out.println( manufacture + " computer starts." );

}

public void process(String fileName)

{

            System.out.println( manufacture + " computer is processing " + fileName );

}

public void shutdown ()

{

            System.out.println( manufacture + " computer is shut down);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote