Create objects of student class by calling default, JAVA Programming

Assignment Help:

Create objects of student class by calling default

Create objects of student class by calling default, parameterize and copy constructor Call student class different methods on these objects.

Student client code

// File Test.java

 

/* This class create Student class objects and demonstrates

how to call various methods on objects

*/

public class Test{

 

public static void main (String args[]){

 

// Make two student obejcts

Student s1 = new Student("ali", 15);

Student s2 = new Student(); //call to default costructor

 

s1.print(); // display ali and 15

s2.print(); // display not set and 100

 

s2.setName("usman");

s2.setRollNo(20);

 

System.out.print("Student name:" + s2.getName());

System.out.println(" rollNo:" + s2.getRollNo());

 

System.out.println("calling copy constructor");

Student s3 = new Student(s2); //call to copy constructor

 

s2.print();

s3.print();

s3.setRollNo(-10); //Roll No of s3 would be set to 100

s3.print();

/*NOTE: public vs. private

A statement like "b.rollNo = 10;" will not compile in a

client of the Student class when rollNo is declared

protected or private

*/

} //end of main

} //end of class

#question..

 


Related Discussions:- Create objects of student class by calling default

What is inheritance in java explain with example, What is Inheritance in ja...

What is Inheritance in java Explain with example? Code reusability is claimed to be a key advantage of object-oriented languages over non-object-oriented languages. Inheritance

Develop an android prize wheel, Project Description: I am seeking someon...

Project Description: I am seeking someone to prepare a small Android app for a promotional offer. It must be designed for use on an Android tablet. Fundamentally, a user will

What types of new jobs are created because of computing, What types of new ...

What types of new jobs are created because of computing? And that old professions are being eliminated? Because of computing whereas people are getting benefits from automated

Train ticket, Write a program that manages a list of train tickets, JAVA Pr...

Write a program that manages a list of train tickets, JAVA Programming

Statements and operators, Operator Functionality E x...

Operator Functionality E x ample/Explanation = Sets one value equal to another counter=0  Sets the counter to equivale

Explain the term- comparing strings, Explain the term- Comparing Strings ...

Explain the term- Comparing Strings For comparing Strings never use == operator, use equals method of String class. - == operator compares addresses (shallow comparison) whi

La Food Restaurant Program, The fancy new French restaurant La Food is very...

The fancy new French restaurant La Food is very popular for its authentic cuisine and high prices. This restaurant does not take reservations. To help improve the efficiency of the

Explain the char data type in java, Explain the char data type in java? ...

Explain the char data type in java? A char is a single character in which a letter, a digit, a punctuation mark, a tab, a space or something same. A char literal is a single on

Collection, how would I become expert in collection framework

how would I become expert in collection framework

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd