package com.codegym.task.task14.task1412;
/*
Implement the printMainInfo method
*/
public class Solution {
public static void main(String[] args) {
//Object obj = new Movable();
// Movable movable = (Movable) obj;
// Rectangle drawable = new Rectangle();
Rectangle drawable =new Rectangle();
Circle movable=new Circle();
printMainInfo(drawable);
printMainInfo(movable);
}
public static void printMainInfo(Object object) {
if ( object instanceof Rectangle ){
object.draw();
}
else if ( object instanceof Circle){
object.move();
}
//write your code here
}
static interface Movable {
void move();
}
static class Circle implements Movable {
public void draw() {
System.out.println("Can be drawn");
}
public void move() {
System.out.println("Can be moved");
}
}
static interface Drawable {
void draw();
}
static class Rectangle implements Drawable {
public void draw() {
System.out.println("Can be drawn");
}
public void move() {
System.out.println("Can be moved");
}
}
}
Help me please.Getting error
Under discussion
Comments (6)
- Popular
- New
- Old
You must be signed in to leave a comment
Anonymous #10410173 Full Stack Developer
3 March 2020, 19:21
+3
hidden #10444738
11 October 2019, 05:53
Just swap your if else if statement.
0
Denis
12 April 2019, 23:10
You changed main method.
You shouldn't do it.
Use narrowing.
Like this:
+1
Sindhura
16 October 2018, 07:17
cannot find symbol symbol: method draw() location: variable object of type java.lang.Object:
Solution.java, line: 21, column: 19
cannot find symbol symbol: method move() location: variable object of type java.lang.Object:
Solution.java, line: 24, column: 19
0
Learner
16 October 2018, 11:05
draw() and move() methods are not a part of the class Object.
They are part of Circle and Rectangle class. Hence, objects of Circle and Rectangle class can call these methods.
Again, as suggested earlier, type cast object and then call these methods.
Also, you have to check whether object is instance of Drawable or Movable interface not Circle or Rectangle.
+3
Sindhura
20 October 2018, 08:19
here movable and drawaable objects are of class rectangle and Circle and they are evn implementing drawable and movable inerfaces..So I caalled them directly with objects..
Am i wrong?Still I am not gettig what to do
0