Example of overloading

Assignment Help JAVA Programming
Reference no: EM13742534

Question 1

In object oriented programming, every object...
(A) is an attribute of another object
(B) is an instance of a class
(C) inherits from a class
(D) has recursive methods
Which one of the above is correct? _______________________

Question 2

Select the correct statement or statements regarding object oriented programming in Java:
(A) Inheritance models the IS-A relationship, in which the objects of the subclass are also objects of the superclass.
(B) The number of methods in a superclass is always higher than in each of its subclasses.
(C) Two subclasses of the same superclass always have the same number of methods.
(One of more correct answer is possible)

Answer(s): ______________________

Question 3

Select the correct answer/s regarding visibility in Java. When an attribute (instance variable) is defined as private in a class:
(A) it can be accessed only once in the program
(B) it can be accessed and modified only from methods of that class
(C) it can be accessed and modified only from private methods of that class
(D) it can be accessed and modified only from methods of that class and its subclasses
(E) it can be accessed and modified only from methods of that class and its superclass
(F) it can be accessed but it cannot be modified
(One of more correct answer is possible)

Answer(s): ______________________

Question 4

Which of the following sentences about constructors in Java are correct?
(A) The return type void must be included in the declaration of a constructor
(B) A class can have several constructors
(C) Constructors are used to create objects (instances) of a class
(D) Constructors need to receive at least one argument
(E) Constructors are special methods that cannot be overloaded
(One of more correct answer is possible)

Answer(s): ______________________

Question 5

Given two points p1 and p2 represented in the bidimensional space by coordinates x and y, the length of the line that connects these two points (i.e. the distance between these two points) is given by the formula:

d = √(x2 - x1)2 + (y2 - y1)2

where x1 and y1 represent the coordinates of p1, and x2 and y2 represent the coordinates of p2.

The following two Java classes, Point and Line, represent bidimensional points and straight lines that connect two points.

public class Point {
private double x = 0;
private double y = 0;

public Point(int a, int b) {
x = a;
y = b;
}

public double getX() {
return x;
}

public double getY() {
return y;
}
}

public class Line {
private Point p1;
private Point p2;

public Line (Point firstPoint, Point secondPoint) {
p1 = firstPoint;
p2 = secondPoint;
}
}

We want to implement the method length() in the class Line. This method calculates the distance of the two points that are connected by a straight line. Would the following implementations of length() be correct?

NOTE: The method Math.sqrt(x) calculates the square root of x and the method Math.pow(x,2)calculates x squared.
(Please mark a "X" for the correct answer)
public double length() {
return Math.sqrt(Math.pow(p2.getX()-p1.getX(),2)
+ Math.pow(p2.getY()-p1.getY(),2));
}
Answer: YES ( ) NO ( )

public double length() {
return Math.sqrt(Math.pow(p2.getX()-p1.getY(),2)
+ Math.pow(p2.getY()-p1.getX(),2));
}
Answer: YES ( ) NO ( )

public double length() {
return Math.sqrt(Math.pow(p2.x-p1.x,2)
+ Math.pow(p2.y-p1.y,2));
}
Answer: YES ( ) NO ( )

public double length() {
return Math.sqrt(Math.pow(p2.x-p1.y,2)
+ Math.pow(p2.y-p1.x,2));
}
Answer: YES ( ) NO ( )

Question 6

Given the following class:
public class Student {
static int counter = 0;
int id;

public Student() {
id = counter;
counter++;
}

public static void main(String[] args){
Student s1 = new Student();
Student s2 = new Student();
Student s3 = new Student();
System.out.println(s1.id + "" + s2.id + "" + s3.id);
System.out.println(s1.counter + "" + s2.counter + "" + s3.counter);
}
}

PART A) Which is the result printed on screen of executing:
System.out.println(s1.id + "" + s2.id + "" + s3.id);
(A) 000
(B) 001
(C) 012
(D) 111
(E) 123
(F) 222
(G) 234
(H) 333
Answer: __________________________

PART B) Which is the result printed on screen of executing:
System.out.println(s1.counter + "" + s2.counter + "" + s3.counter);
(A) 000
(B) 001
(C) 012
(D) 111
(E) 123
(F) 222
(G) 234
(H) 333
Answer: __________________________

Question 7

Given MyClass and YourClass classes, as shown below, what line should replace //...[Here]... in YourClass?
public class MyClass {
private int a;
public MyClass (int a) {
this.a = a;
}
}

public class YourClass extends MyClass {
private int b;
public YourClass (int a, int b) {
//...[Here]...
this.b = b;
}
}

(A) this.a = a;
(B) MyClass(a);
(C) super(a);
(D) YourClass(a);
(E) a=a;

Answer: ___________________________

Question 8

Which of the following options is an example of overloading:

(A) Two methods with the same name that are implemented in the same class, and that have the same number and type of parameters

(B) Two methods with the same name that are implemented in different classes and that have the same number and type of parameters

(C) Two methods with the same name that are implemented in the same class, and that have the same number of parameters but of different types

(D) Two methods with the same name that are implemented in different classes, and that have the same number of parameters but of different types

(E) One method implemented in one class, and another method with the same name, number and type of parameters implemented in a class that inherits from the first one

Reference no: EM13742534

Questions Cloud

Journalize entries for disposal of equipment : Beka Company owns equipment that cost $50,000 when purchased on January 1, 2008. It has been depreciated using the straight-line method based on estimated salvage value of $5,000 and an estimated useful life of 5 years.
Management communication in the past decade : The purpose of this short research paper is to ensure proper understanding and application of APA style as required in all Ashford courses. Using the Ashford Online Library, develop an annotated bibliography on one of the following factors that ha..
Barriers interfering with the communication : Can you identify and reduce the likelihood of barriers interfering with the communication. Give examples. Use at least one resource to support your key points. Respond to at least two of your fellow students' posts with your response to some of th..
Intercultural communication competence help you personally : Is it important for you to achieve a certain level of intercultural communication competence. Would enhanced intercultural communication competence help you personally. Professionally. Academically. Include examples in your submission and use at l..
Example of overloading : Implement in different classes and that have the same number and type of parameters - Inheritance models the IS-A relationship, in which the objects of the subclass are also objects of the superclass - Different classes and that have the same number ..
Designing the job : "Designing the Job" According to your textbook Nelson and Quick, (2015) Results Only Work Environment (ROWE) allows employees to work completely flexible schedules based on their ability to meet measurable goals. Employees are allowed to come and ..
Summarize importance of political change took place in india : Summarize the importance of the political, economic, and social changes took place in India after independence.
A comparative development approach of brain asymmetry : Prepare a review on topic A COMPARATIVE DEVELOPMENT APPROACH OF BRAIN ASYMMETRY: ZEBRAFISH (Danio rerio) AND MEDAKA (Oryzias latipes)
Write an essay on the george herbert walker bush : Write an essay on the George Herbert Walker Bush. each vocabulary should be one slide. for each vocabulary, brief explain what it is.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Create a guessing game

Create a guessing game where the user enters an integer between 1 and 10.

  Declare another television object called portable

Add to the comment header as indicated at the top of the program.

  Test the invoice application

Study the error message and note the line number in the statement in the InvoiceApp class that caused the crash. Then click on the link to that line of the code.

  What do you mean by nested inner class what special

q1. what is a nested inner class? what special privileges does a nested inner class have? give an example of how you

  Mining information from sales data is a common task in both

mining information from sales data is a common task in both traditional and online stores. past sales information can

  Pronouns, and prepositions

Type addKeyword(): for each word on each page, add to a (keyword, URLs) list or dictionary, excluding articles, pronouns, and prepositions. For example:

  Write java method which fills the array with random numbers

Write a Java method which takes an integer array parameter and fills the array with random numbers between 1 and 1000, including 1 and 1000.

  You need to find out the average score how many scores are

suppose that you have an array of baseball scores type integer called scores. the values in the array are ordered from

  Statistics list program

You will also modify your program to accept input from an input file and print a report to an output file. These files are to be named by the user at runtime.

  Create a circle class

create acircle class, which has one field, the radius. the class should contains two constructors: a no-argument constructor that set the radius to zero, and a constructor that takes a parameter to set the radius.

  Create the look for two gui applications

Create the look for two GUI applications. You WILL NOT be getting the applications to do anything. We are only interested in seeing how well you can arrange the GUI components onto the window

  In cryptarithmetic puzzles mathematical equations are

in cryptarithmetic puzzles mathematical equations are written by using letters. each letter can be digit from 0 to 9

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd