Question

Java please answer A to I please dont type the answer on paper please use the computer

A.   Explain why alpha cannot be accessed by other members of its class.
B.   In the program, how can you determine the type of access modifier?
C.   Describe the differences and similarities of beta and gamma in program, within the context of access specifiers and class member accessibility.

// Public vs private access. class Myclass { private int alpha; // private access public int beta; // public access int gamma

D.   Explain how objects, a and b, are passed to the method.
E.    Why primitive type cannot be used in the objects of this program?
F.   Explain how the call or changes of objects, a and b, impact the output of the program.

// Objects are passed through their references. class Test { int a, b; Test (int i, int i) { a = i; b = 3; /* Pass an object.

G.   How does void ovlDemo() and int ovlDemo() impact the output of the program?
H.   What will the program output when the method is overloaded with the same type and numbers of parameters?

Create, compile and run the below program: // Demonstrate method overloading. class Overload { void ovlDemo () { - First vers

I.Applying the concept of method overloading, create, compile and run a Java program that calculates and displays the result for each overload:

Given int P = 30, double Q = 50.00, float R = 70.5

  • First overload: return P + 1/3P
  • Second overload: return Q + 1/2Q
  • Third overload: return R + 1/4R
0 0
Add a comment Improve this question Transcribed image text
Answer #1

A) A member variable or field declared as private can only be accessed by within the class or through its methods,if a object for that class is declared inside another class then only fields declared as public can be accessed.

B)Access modifiers are specified along with the member variables at the time of its declaration.For example public int beta is declared in class MyClass ,so public is the access modifier here.

C)The access specifier used for beta is public and for gamma nothing is specified so default access specifier is considered.As beta is declared as public it can be accessed by any class in the program without any errors,but as gamma is declared with a default access specifier thus it can only be access by class present in the same package and any class outside the package cannot access gamma results in a compilation error.

D)Objects a and b are passed through pass-by reference.Although in Java pass-by-value is used for non-primitive type such as an object pass-by-reference is used.Thus any changes made to the object will reflect in the main object as long as we don't make the object to point to any other address.

E)Question is not clear

F)As i told earlier any changes to copy of reference of the objects inside the method will result in changes to the object itself.Thus ob.a=35(i.e 15+20) and ob.b=-20

G)void ovlDemo() does not return any data but whereas int ovlDemo() return a data of type int provided the two numbers have different signature i.e the parameters should either have different datatype or the number of parameters should be different.

H) A method overloaded should always have different number of parameters or different type of parameters.If methods with same number and same type of of parameters are overloaded then compilation error will be generated.The return type of the method is not taken into consideration while differentiating methods

I)class overload{

double cal(int a)

{ return a+(1/(3a));

}

double cal(double a)

{return a+(1/(2a));

}

double cal(float a)

{ return a+(1/(4a));

}

}

class OverloadDemo{

public static void main(String args[]){

overload ob=new overload();

int P=30 ;double Q=50.00 ;float R=70.5

double ans;

ans=ob.cal(P);

system.out.println("Result of first overload is "+ans);

ans=ob.cal(Q);

system.out.println("Result of second overload is "+ans);

ans=ob.cal(R);

system.out.println("Result of third overload is "+ans);

}

}

Add a comment
Know the answer?
Add Answer to:
Java please answer A to I please dont type the answer on paper please use the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • this is a jave program please help, I'm so lost import java.util.Scanner; public class TriangleArea {...

    this is a jave program please help, I'm so lost import java.util.Scanner; public class TriangleArea { public static void main(String[] args) { Scanner scnr = new Scanner(System.in);    Triangle triangle1 = new Triangle(); Triangle triangle2 = new Triangle(); // Read and set base and height for triangle1 (use setBase() and setHeight())    // Read and set base and height for triangle2 (use setBase() and setHeight())    // Determine larger triangle (use getArea())    private int base; private int height; private...

  • How to build Java test class? I am supposed to create both a recipe class, and...

    How to build Java test class? I am supposed to create both a recipe class, and then a class tester to test the recipe class. Below is what I have for the recipe class, but I have no idea what/or how I am supposed to go about creating the test class. Am I supposed to somehow call the recipe class within the test class? if so, how? Thanks in advance! This is my recipe class: package steppingstone5_recipe; /** * *...

  • The code is attached below has the Account class that was designed to model a bank account.

    IN JAVAThe code is attached below has the Account class that was designed to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and withdraw funds. I need creat program using the 2 java programs.Create two subclasses for checking and savings accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn.I need to write a test program that creates objects of Account,...

  • Use an accessor and mutator as follows: Remove the addFuel method from class Car Replace the...

    Use an accessor and mutator as follows: Remove the addFuel method from class Car Replace the call to addFuel in the main program with a call to the accessor and mutator for the fuel amount to achieve the same effect (add 5 gallons of fuel to the existing fuel in the Toyota Camry). Test your program again to make sure it works and produces the same output. Part 2: Add functions to remove duplicate code * In the main program,...

  • Draw a UML class diagram (with associations) to show the design of the Java application. public...

    Draw a UML class diagram (with associations) to show the design of the Java application. public class OOPExercises {     public static void main(String[] args) {         //A objA = new A();         B objB = new B();         System.out.println("in main(): ");         //System.out.println("objA.a = "+objA.getA());         System.out.println("objB.b = "+objB.getB());         //objA.setA (222);         objB.setB (333.33);         //System.out.println("objA.a = "+objA.getA());         System.out.println("objB.b = "+objB.getB());     } } public class A {     int a = 100;     public A() {...

  • What display is produced by the execution of this JAVA program if we make the following...

    What display is produced by the execution of this JAVA program if we make the following call f(0,0). Please explain your answer public class function {    static void f(int x){        System.out.println(1);    }    static void f(double x){        System.out.println(2);    }    static void f(char x){        System.out.println(3);    }    static void f(long x){        System.out.println(4);    }    public static void main(String[] args) {       } }

  • NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the...

    NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the current displayed customer PLEASEEEEEEEEEE package bankexample; import java.util.UUID; public class Customer { private UUID id; private String email; private String password; private String firstName; private String lastName;    public Customer(String firstName, String lastName, String email, String password) { this.id = UUID.randomUUID(); this.firstName = firstName; this.lastName = lastName; this.email = email; this.password = password; } public String getFirstName() { return firstName; } public void setFirstName(String...

  • JAVA 3files seprate 1.Classroom.java 2.ClassroomTester.java (provided) 3.Student.java(provided) Use the following files: ClassroomTester.java import java.util.ArrayList; /** *...

    JAVA 3files seprate 1.Classroom.java 2.ClassroomTester.java (provided) 3.Student.java(provided) Use the following files: ClassroomTester.java import java.util.ArrayList; /** * Write a description of class UniversityTester here. * * @author (your name) * @version (a version number or a date) */ public class ClassroomTester { public static void main(String[] args) { ArrayList<Double> grades1 = new ArrayList<>(); grades1.add(82.0); grades1.add(91.5); grades1.add(85.0); Student student1 = new Student("Srivani", grades1); ArrayList<Double> grades2 = new ArrayList<>(); grades2.add(95.0); grades2.add(87.0); grades2.add(99.0); grades2.add(100.0); Student student2 = new Student("Carlos", grades2); ArrayList<Double> grades3 = new...

  • In Java Create a testing class that does the following to the given codes below: To...

    In Java Create a testing class that does the following to the given codes below: To demonstrate polymorphism do the following: Create an arraylist to hold 4 base class objects Populate the arraylist with one object of each data type Code a loop that will process each element of the arraylist Call the first ‘common functionality’ method Call the second ‘common functionality’ method Call the third ‘common functionality’ method Verify that each of these method calls produces unique results Call...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT