1.a) i) The Java bytecode or Java classes are compiled to machine code and loaded into memory by the Java Virtual Machine for the first time.
a) ii)An instance is a specific realization of any object in OOP.The creation of instance is known as instantiation.An object varied in number of ways.Each realized variation of the object is instance.Each time when a program runs,it is an instance of program
Objects are created by constructor and it gets destroyed by destroyer.
Instantiation done by using new keyword.
Syntax:className objName=new className(input parameters)
a)III) when object is no longer in usage then garbage collector reclaims it's memory and reuse it for future memory allocation.Hence as long as object is in usage, they stay in memory.
a) iv)In java as soon as object has no longer any references,it becomes eligible for deletion.Once the object is no longer referenced and therefore it is not reachable by application code,the garbage collector removes and reuse the unused memory.
2.The class is defined as a blueprint or template that describes the behavior or state of an object.
It has main components like variable,method and constructor in java.
Syntax: <access specifier> class className{
// Class body
}
Accessibility Modifiers:
Java provides access through priavte,public and protected.
Private
It is specified with keyword private.It is accessible only within the class in which it is declared.Anyother class of same object will not be able to access.
Protected
It is specified with protected keyword.The method or datamember declared protected are accessible within same package or subclass in different package.
Public
It is specified with public keyword.It can be accessed from everywhere in the program i.e widest scope among all other access Modifiers.
Non-standard accessibility modifier:
JAVA basic quiz. 1. a) In order to run a java program, the computer must first...
1. What happens in the Java Virtual Machine (JVM) when the following line is processed? MyClass n = new MyClass(); A. Nothing, the line is skipped, since no parameters are defined B. An object of type MyClass is created, no reference is created C. A reference to an object of type MyClass is created, no object is created D. Both a reference and an object of type MyClass are created 2. Which of the following is true? A. A single...
Question 1 1 pts Which of the following is not a valid class name in Java? O MyClass MyClass1 My_Class MyClass# Question 2 1 pts Which of the following statements is False about instance variables and methods? Instance variables are usually defined with private access modifier. Instance variables are defined inside instance methods. Instance methods are invoked on an object of the class that contains the methods. A class can have more than one instance variables and methods. Question 3...
Write a complete Java program to create three types of counters as follows: The first counter increases its value by one. The second counter increases its value by two. The third counter increases its value by three. Please follow these notes: Create one class for all counter types. The name of the class is Three_type_counter. Define a constructor method that initial values for all counters to 7 when the class object created. Create method for each counter as: count1, count2...
Creating a Shell Interface Using Java This project consists of modifying a Java program so that it serves as a shell interface that accepts user commands and then executes each command in a separate process external to the Java virtual machine. Overview A shell interface provides the user with a prompt, after which the user enters the next command. The example below illustrates the prompt jsh> and the user’s next command: cat Prog.java. This command displays the file Prog.java on...
In Java,enhace the program base on the first one. 1. You are going to design (and code) a class called Name. The class Name will contain three properties: first, the first name which is a String initial, the middle initial, which is a single character. last, the last name, which is a String The class has three constructors: A default constructor, which accepts no parameters, calls constructors for the first and last name and sets the initial equal to a...
JAVA PROGRAM USING ECLIPSE. THE FIRST IMAGE IS THE
INSTRUCTIONS, THE SECOND IS THE OUTPUT TEST CASES(WHAT IM TRYING TO
PRODUCE) BELOW THOSE IMAGES ARE THE .JAVA FILES THAT I HAVE
CREATED. THESE ARE GeometircObject.Java,Point.java, and
Tester.Java. I just need help making the Rectangle.java and
Rectangle2D.java classes.
GeometricObject.Java:
public abstract class GeometricObject {
private String color = "white"; // shape color
private boolean filled; // fill status
protected GeometricObject() { // POST: default shape is unfilled blue
this.color = "blue";...
**Program must compile under Ubuntu! (35 pts) Write a C++ program A4p2.cpp with a class of your own design. The class should contain a protected int member variable var, which is initialized with an integer value between 1 and 50 in a constructor that takes an integer parameter. The class should contain a public member function called playthat should print out a sequence of integers as a result of iteratively applying a math function f to the member variable var...
***Program must compile under Ubuntu! (35 pts) Write a C++ program A4p3.cpp with a class that is a derived class of your class from problem 2. Add a private intmember variable var2 to this class. Initialize the member variables var and var2 with values between 1 and 50 using a constructor that takes two integer parameters. Add a public member function called getsp that should print out the sum and product of var and var2. In your main function, create...
Java - Object lifecycle and memory management
Consider the following Java programs: Program Code publ ic cl ass A a publ ic st at ic voi d mai n( St ri ngl1 args) t hr ows Excepti on whi I e (true) for (i nt i -0 ; i <1000000; i ++) Cbj ect obj new Obj ect ); gi ve JVM 100ms ti me to run gar bage col l ect i on Thr ead. sl eep( 100): i...
in JAVA Which of the following attributes would be MOST appropriate for a class called Book, that represents a book in a library? libraryName, location, libraryHours title, author, typeOfBook pages, cost, shipping anything, anytime, anywhere Which of the following statements is FALSE regarding constructors? A constructor allows you to set up an object once it is instantiated. A constructor does not have a return type. A constructor must have the same name as the name of the class. You can...