Java Constructor Exercises Questions
Java Constructor Exercises Questions
6:06:22 PM
Mon, May 13, 2024
Search
Logic of program
Part 1: Design a class named Circle.
Ans:
class Circle{
Part 2: Construct three circle objects with radius 2.0, 12, and 24
Ans :
Circle obj1= new Circle(2.0);
Circle obj2= new Circle(12);
Circle obj3= new Circle(24);
Note: object create only main funsion
Circle(double x){
redious =x;
}
paramiter radius pass when object create.
Ad removed. Details
Part 4: A no-arg constructor set the default value of radius to 1.
https://www.worldtimetech.com/en/single?id=java-constructor-exercises-questions 1/12
5/13/24, 6:06 PM Java Constructor Exercises Questions
Ans :
Circle(){
redious =1;
}
class Circle{
double redious;
double area;
Circle(double x){
redious =x;
area=3.1416*redious*redious;
}
void display(){
System.out.println("redious "+redious);
System.out.println("area "+area);
}
Circle(){
redious =1;
}
double getArea(){
area=3.1416*redious*redious;
return area;
}
}
public class JavaApplication24 {
public static void main(String[] args) {
Circle obj1= new Circle(2.0);
Circle obj2= new Circle(12);
Circle obj3= new Circle(24);
obj1.display();
obj2.display();
obj3.display();
System.out.println("arear "+arear);
System.out.println("arear2 "+arear2);
System.out.println("arear3 "+arear3);
}
Related Content
https://www.worldtimetech.com/en/single?id=java-constructor-exercises-questions 2/12
5/13/24, 6:06 PM Java Constructor Exercises Questions
https://www.worldtimetech.com/en/single?id=java-constructor-exercises-questions 3/12
5/13/24, 6:06 PM Java Constructor Exercises Questions
https://www.worldtimetech.com/en/single?id=java-constructor-exercises-questions 4/12
5/13/24, 6:06 PM Java Constructor Exercises Questions
8 puzzle problem
https://www.worldtimetech.com/en/single?id=java-constructor-exercises-questions 5/12
5/13/24, 6:06 PM Java Constructor Exercises Questions
https://www.worldtimetech.com/en/single?id=java-constructor-exercises-questions 6/12
5/13/24, 6:06 PM Java Constructor Exercises Questions
https://www.worldtimetech.com/en/single?id=java-constructor-exercises-questions 7/12
5/13/24, 6:06 PM Java Constructor Exercises Questions
https://www.worldtimetech.com/en/single?id=java-constructor-exercises-questions 8/12
5/13/24, 6:06 PM Java Constructor Exercises Questions
https://www.worldtimetech.com/en/single?id=java-constructor-exercises-questions 9/12
5/13/24, 6:06 PM Java Constructor Exercises Questions
https://www.worldtimetech.com/en/single?id=java-constructor-exercises-questions 10/12
5/13/24, 6:06 PM Java Constructor Exercises Questions
Recent Post
Simple calculator program in java using swing
8 puzzle problem
Top Balanced Meals Plan for Breakfast Lunch and Dinner in Seven Days
https://www.worldtimetech.com/en/single?id=java-constructor-exercises-questions 11/12
5/13/24, 6:06 PM Java Constructor Exercises Questions
Ad removed. Details
Developed by TIS-SK
Importance matters
Troubleshooting
MovieNews
C Program
Information matters
Java Program
Education Help
JavaScript
Our categories
WorldTimeTech provides Movie News, Troubleshooting, and Programming knowledge. Thank You...
https://www.worldtimetech.com/en/single?id=java-constructor-exercises-questions 12/12