Friday, December 13, 2019

Exercise - 3 (Class, Objects)

Exercise - 3 (Class, Objects)

a). Write a JAVA program to implement class mechanism. – Create a class, methods and
invoke them inside main method.

class Student
{
  String name="Raju";
  String _class="B.Tech 1st year";
  int rollno=178;
  public void display()
  {
    System.out.println("Name of the student is:"+name);
    System.out.println("Present qualification of the student is:"+_class);
    System.out.println("Roll number of the student is:"+rollno);
  }

}
class Details
{
  public static void main(String args[])
  {
    Student s1=new Student();
    s1.display();
  }
}


b). Write a JAVA program to implement constructor.

import java.util.Scanner;
class Sports_person
{
int height=164;
  int weight=62;
  Sports_person()
  {
                System.out.print("Enter name of the country:");
                Scanner sc=new Scanner(System.in);
                String country=sc.nextLine();
  System.out.println("Height of the sports person is:"+height+"CM");
  System.out.println("Weight of the sports person is:"+weight+"KG");
System.out.println("He/She belongs to the country:"+country);
 
  }
}
class Olimpics
{
  public static void main(String args[])
  {
  Sports_person sp=new Sports_person();
  }

}

No comments:

Post a Comment

JAVA PROGRAMMING ASSIGNMENT 2 QUESTIONS

SIR C R REDDY COLLEGE OF ENGINEERING, ELURU DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING JAVA PROGRAMMING ASSIGNMENT 2 QUESTIONS ...