Knowee
Questions
Features
Study Tools

A class Circle is defined in the following code:public class Circle { int radius; static String name; void getPerimeter() { } static void getArea() { }}Let c be an instance of Circle, which of the statements are correct?System.out.println(c.radius);c.getArea();c.getPerimeter();System.out.println(c.name);

Question

A class Circle is defined in the following code:public class Circle { int radius; static String name; void getPerimeter() { } static void getArea() { }}Let c be an instance of Circle, which of the statements are correct?System.out.println(c.radius);c.getArea();c.getPerimeter();System.out.println(c.name);

🧐 Not the exact question you are looking for?Go ask a question

Solution

The following statements are correct:

  1. System.out.println(c.radius); - This is correct because 'radius' is an instance variable and can be accessed by an instance of the class.

  2. c.getPerimeter(); - This is correct because 'getPerimeter' is an instance method and can be called by an instance of the class.

  3. System.out.println(c.name); - This is correct because 'name' is a static variable and can be accessed by an instance of the class.

The following statement is incorrect:

  1. c.getArea(); - This is incorrect because 'getArea' is a static method and should be called by the class itself, not by an instance of the class. The correct way to call this method would be Circle.getArea();

This problem has been solved

Similar Questions

public abstract class Shape  {      private int x; private int y;      public abstract void draw();      public void setAnchor(int x, int y) {                  this.x = x;                  this.y = y;      }} Which two classes use the Shape class correctly? (Choose two.)Select one or more:a.public abstract class Circle extends Shape {       private int radius;}b.public class Circle extends Shape  {     private int radius;     public void draw();}c.public class Circle extends Shape   {     private int radius;     public void draw() {/* code here */}}d.public class Circle implements Shape  {        private int radius;}

What will be the output of the following code?public class Circle {    private double radius;    public Circle(double radius) {        this.radius = radius;    }    public double getArea() {        return Math.PI * radius * radius;    }    public static void main(String[] args) {        Circle c = new Circle(2.5);        System.out.println(c.getArea());    }}Question 14Answera.3.14b.6.28c.19.63d.Compilation error

Given the declaration Circle x = new Circle(), which of the following statements is most accurate?                           Group of answer choicesYou can assign an int value to x.x contains a reference to a Circle object.x contains an object of the Circle type.x contains an int value.

orrect answerPredict the output of the given Java Program. class Circle {    static String s = " ";    protected Circle() {        s += "Circle ";    } } class SemiCircle extends Circle {    private SemiCircle() {        s += "Semi ";    } }   class SemisemiCircle extends Circle {    private SemisemiCircle() {        s += "SemiSemi ";    }    public static void main(String[] args) {         new SemisemiCircle();        System.out.println(s);    } }OptionsCircle SemiSemiSemiCircleSemi

Select the correct answerWhich of these method of Object class is used to obtain class of an object at run time?OptionsClass getclass()void getclass()get()None of the mentioned

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.