Question:
- Create a class called ‘Actors’
- Have static fields String role=”Hero”, String language = “tamil”.
- Have non-static fields String movie_name, boolean hit
- Have main method in it.
- Now Create instances as below.
Actors vijay = new Actors();
Actors ajith = new Actors(); - Using above instances, assign values to non-static fields.
- Now call act() method using instances.
- Observe the error message. Try to fix it.
- Inside act method definition, print movie_name and hit information.
- Inside act method definition, print role and language details.
class Actors
{
static String role = "Hero"; //staic variable iniiated
static String language ="tamil";
String Movie_name; // non-static variable initated
boolean first_movie ; // boolean statemnet statment condition tru or not
public static void main(String[] args) //main method
{
Actors Thala_ajith= new Actors(); //object creation
Actors Thalpathi_vijay =new Actors();
Thala_ajith.Movie_name = " En Veedu En Kanavar"; // created object assign the variable
Thalpathi_vijay.Movie_name = "Poove Unakkaga";
Thala_ajith.first_movie=true;
Thalpathi_vijay.first_movie=true;
Thala_ajith.act();// method calling
Thalpathi_vijay.act();
}
void act() // method signature act()
{ // Below method defination
System.out.println("movie_name:"+Movie_name +"first_movie:"+ first_movie);
System.out.println("role:"+ role + "language:" + language);
}
}
Output:-
prasanth362k@prasanth362k-HP-Laptop-15s-fq5xxx:~/Documents/OJM$ java Actors
movie_name: En Veedu En Kanavarfirst_movie:true
role:Herolanguage:tamil
movie_name:Poove Unakkagafirst_movie:true
role:Herolanguage:tamil