Static Method Calling Program

Question:

  1. Create a class called ‘Actors’
  2. Have static fields String role=”Hero”, String language = “tamil”.
  3. Have non-static fields String movie_name, boolean hit
  4. Have main method in it.
  5. Now Create instances as below.
    Actors vijay = new Actors();
    Actors ajith = new Actors();
  6. Using above instances, assign values to non-static fields.
  7. Now call act() method using instances.
  8. Observe the error message. Try to fix it.
  9. Inside act method definition, print movie_name and hit information.
  10. 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

Leave a comment

Design a site like this with WordPress.com
Get started