public class Cat {
String name;
int age;
static int count = 0;
public static void main(String[] args) {
Cat smudge = new Cat();
smudge.age = 3;
smudge.name = "Smudge";
count++;
Cat fluffy = new Cat();
fluffy.age = 5;
fluffy.name = "Fluffy";
count++;
Dog sheru = new Dog();
sheru.dog="akaakk";
System.out.println(sheru.dog);
System.out.println("We created a cat named " + smudge.name + ". His age is " + smudge.age);
System.out.println("We created a cat named " + fluffy.name + ". His age is " + fluffy.age);
System.out.println("Total number of cats = " + count);
}
public class Dog{
String dog;
}
}
1-what is error and why?
2-if we make Cat class as static then what will happened? modifier static is not allow here ?
what is error and why ?
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Khurram
24 October 2018, 16:18
you are referencing non static class Dog in static method main
0
Ashish RajAnand
25 October 2018, 10:04
why can i not use static class Dog in static method main ?
0